在 PHP 中关闭包含的文件



我正在尝试通过方法传递pro_id来更改MySQL查询中的pro_id。是打印表。但它正在给予

注意:常量服务器已在 C:\WAMP64\WWW\DASHBOARD\CONFIG2 中定义。第 2 行的 PHP
注意:常量用户名已在 C:\WAMP64\WWW\DASHBOARD\CONFIG2 中定义。第 3 行的 PHP
注意:常量密码已在 C:\WAMP64\WWW\DASHBOARD\CONFIG2 中定义。第 4 行的 PHP
注意:常量数据库已在 C:\WAMP64\WWW\DASHBOARD\CONFIG2 中定义。第 5 行的 PHP

这些错误。

我的代码是这样的,

<?php
// Defining function
function project($a){
            echo '<DOCTYPE html>
            <head>
                <link rel="stylesheet" type="text/css" href="http://localhost/Dashboard/css/table_css.css">
            </head>
            <section>
            <body>';
         include("C:wamp64wwwDashBoardConfig2.php");
          $sql = "select total_tc,passed,failed,blocked, (total_tc-passed-failed-blocked) as notrun from (select * from (select version_id as version_id from testcases) as t0, (select count(tc_id) as total_tc from testcases where testcases.pro_id=$a) as t,(select count(tc_result) as passed from executions join testcases on testcases.id=executions.parent_id where tc_result='p' and testcases.pro_id=$a  )as t2,
                        (select count(tc_result) as failed from executions join testcases on testcases.id=executions.parent_id where tc_result='f' and testcases.pro_id=$a)as t3,(select count(tc_result) as blocked from executions join testcases on testcases.id=executions.parent_id where tc_result='b' and testcases.pro_id=$a)as t4) as final where version_id= 1 limit 1;";
          $query = mysqli_query($db, $sql);
          echo'<div class="tbl-header">
                <table cellpadding="0" cellspacing="0" border="0">
                    <thead>
                        <tr>
                         <th>Total Testcase</th>
                         <th>Passed</th>
                         <th>Failed</th>
                         <th>Blocked</th>
                         <th>Not run</th>
                      </tr>
                    </thead>
                </table>
          </div>
       <div class="tbl-content">
         <table cellpadding="0" cellspacing="0" border="0">';
             while ($row = mysqli_fetch_array($query))
               {
               echo '<tr>
                <td>'.$row['total_tc'].'</td>
                <td>'.$row['passed'].'</td>
                <td>'.$row['failed'].'</td>
                <td>'.$row['blocked'].'</td>
                <td>'.$row['notrun'].'</td>
              </tr>';
             }
             echo'
        </tbody>
      </table>
    </div>
  </section>
</html>';
}
// Calling function
for ($x = 1; $x <8; $x++) {
    project($x);
} 
?>

和 Config2.php 文件包含

<?php
   define('SERVER', '192.168.0.7:3306');
   define('USERNAME', 'Deepak');
   define('PASSWORD', 'test@123');
   define('DATABASE', 'dashtest');
   $db = mysqli_connect(SERVER,USERNAME,PASSWORD,DATABASE);
?>

任何人都可以帮我解决这个问题吗?

您将包含带有

常量的文件包含在函数中:

     include("C:wamp64wwwDashBoardConfig2.php");

因此,第二次调用函数时,您将收到这些警告。

将文件包含在函数外部(并在必要时将数据库连接作为参数传递(或改用include_once

最新更新