-1
我从php中检索我的表中的数据。我的代码是在这里:Mysqli_query无法执行并抛出错误
<?php
$con = require('config.php');
?>
<html>
<head><title>Php Practise Web</title></head>
<body>
<?php
$sqlQuery = 'SELECT * FROM customers';
$customersData = mysqli_query($con,$sqlQuery);
if(!$customersData){
die('Error in retrieving :'.mysqli_connect_error($con));
}
else{
while($dataRow = mysqli_fetch_array($customersData, MYSQLI_NUM)){?>
<table>
<tr>
<thead>Customer Name<thead>
<thead>Customer Email<thead>
<thead>Customer Username<thead>
<thead>Customer Age<thead>
</tr>
<tr>
<td><?php echo $dataRow['c_name']?></td>
<td><?php echo $dataRow['c_email']?></td>
<td><?php echo $dataRow['c_username']?></td>
<td><?php echo $dataRow['c_age']?></td>
</tr>
</table>
<?php
}
}
?>
</body>
</html>
但它抛出一个错误这样 这里是我的config.php代码
<?php
$con = mysqli_connect("localhost","root","","phppractise");
if(mysqli_connect_errno()){
echo "Failed to connect to Mysql : ".mysqli_connect_errno();
}
else{
echo "Database Connected";
}
>
从最初的其实?我正在与我的数据库建立连接,然后从名为“customers”的表中检索数据。我在mysqli_query中传递连接变量和查询变量,但它仍然抛出一个错误。请告诉我我的代码错在哪里?
发布'config.php'中的代码。它返回一个整数 - 读取错误。 –
与您之前的问题有任何关系? https://stackoverflow.com/q/46739498/1415724 - 你应该编辑你的问题,以包含config.php文件中的内容。 –
我甚至不知道require()*有*返回值。但看起来返回值是一个整数。 'mysqli_query()'期待一个'mysqli'连接对象。哪里是? – David