Php mySQLi没有正确地选择数据
我正在从mysql转换到mysqli。做一些教程。尽管阅读并用谷歌搜索该主题,但没有获得太多成功。我尝试了一个准备好的语句,但它一直输出0个结果(即now_rows=0)。当我手动查询mySQL表时,会返回许多结果 mySQLI 5.0.96已启用Php mySQLi没有正确地选择数据,php,mysql,mysqli,Php,Mysql,Mysqli,我正在从mysql转换到mysqli。做一些教程。尽管阅读并用谷歌搜索该主题,但没有获得太多成功。我尝试了一个准备好的语句,但它一直输出0个结果(即now_rows=0)。当我手动查询mySQL表时,会返回许多结果 mySQLI 5.0.96已启用 <? include("conn.php"); // SELECT sql query $sql = "SELECT id, rotation, assignedRad FROM sched_main WHERE thedate = ?";
<?
include("conn.php");
// SELECT sql query
$sql = "SELECT id, rotation, assignedRad FROM sched_main WHERE thedate = ?";
// perform the query and store the result
$query = $conn->prepare($sql);
$thedate='2013-01-02';
$query->bind_param('s', $thedate);
$query->execute();
// if the $query contains at least one row
if ($query->num_rows > 0) {
// output data of each row from $query
while($row = $query->fetch_assoc()) {
echo '<br /> id: '. $row['id']. ' - name: '. $row['rotation']. ' - pass: '. $row['assignedRad'];
}
$query->free();
}
else {
echo '0 results';
}
?>
。。等等
我也有
致命错误:调用未定义的方法mysqli_stmt::mysqli_free()
当我尝试免费()时,我得到:
致命错误:调用未定义的方法mysqli_stmt::free()我不确定调试部分,但在调用
$query->num_rows
之前,可能需要存储数据库执行调用的结果。此外,您可能需要检查准备和执行是否成功
...
if (!$query = $conn->prepare($sql)) {
die($conn->error);
}
$thedate='2013-01-02';
$query->bind_param('s', $thedate);
if (!$query->execute()) {
die($conn->error);
}
$query->store_result();
if ($query->num_rows > 0) {
...
}
有关和的更多信息,请参阅PHP文档
id: - name: - pass:
id: - name: - pass:
id: - name: - pass:
...
if (!$query = $conn->prepare($sql)) {
die($conn->error);
}
$thedate='2013-01-02';
$query->bind_param('s', $thedate);
if (!$query->execute()) {
die($conn->error);
}
$query->store_result();
if ($query->num_rows > 0) {
...
}