我目前正在从事一个图书馆项目,人们可以在其中预订书籍。在其中,我需要查找给定日期某本书的保留副本数。
代码如下。
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "vidunena";
$date = date('Y-m-d');
echo $date;
$days_ago = date('Y-m-d', strtotime('-2 days'));
$day_ago = date('Y-m-d', strtotime('-1 days'));
echo $days_ago;
if (mysqli_connect_error()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "SELECT count(*) FROM reserve WHERE boisbn = '". $bisb. "' AND bodate = '". $days_ago. "'";
$result = mysqli_query($query);
$countt = mysqli_fetch_assoc($result);
$count = $countt['count(*)'];
echo $count;
$conn->close();
?>
但是,当我执行上述cde时,会发生以下错误。
警告:mysqli_query()至少需要2个参数,第50行的C:\ xampp \ htdocs \ Vidunena \ bookres.php中给出1个参数
警告:mysqli_fetch_array()期望参数1为mysqli_result,在第51行的C:\ xampp \ htdocs \ Vidunena \ bookres.php中给出空值
如何解决此问题?
答案 0 :(得分:1)
您仍然必须添加连接
$ con =连接bd
mysqli_query($ con,$ query);