gpt4 book ai didi

php - 关闭php中的包含文件

转载 作者:太空宇宙 更新时间:2023-11-03 11:34:09 24 4
gpt4 key购买 nike

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

NOTICE: CONSTANT SERVER ALREADY DEFINED IN C:\WAMP64\WWW\DASHBOARD\CONFIG2.PHP ON LINE 2
NOTICE: CONSTANT USERNAME ALREADY DEFINED IN C:\WAMP64\WWW\DASHBOARD\CONFIG2.PHP ON LINE 3
NOTICE: CONSTANT PASSWORD ALREADY DEFINED IN C:\WAMP64\WWW\DASHBOARD\CONFIG2.PHP ON LINE 4
NOTICE: CONSTANT DATABASE ALREADY DEFINED IN C:\WAMP64\WWW\DASHBOARD\CONFIG2.PHP ON LINE 5

这些错误。

我的代码是这样的,

<?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:\wamp64\www\DashBoard\Config2.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:\wamp64\www\DashBoard\Config2.php");

所以当您第二次调用您的函数时,您将收到这些警告。

要么在您的函数之外包含该文件(并在必要时将数据库连接作为参数传递),要么改用 include_once

关于php - 关闭php中的包含文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47287567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com