<?php
@ $db = new mysqli('localhost:8080','bookorama','bookorama123','books');
if (!$db) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
} $query = "select * from books where isbn like '%31509%'";
$result = $db->query($query); $num_results = $result->num_rows; echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars(stripslashes($row['title']));
echo "</strong><br />Author: ";
echo stripslashes($row['author']);
echo "<br />ISBN: ";
echo stripslashes($row['isbn']);
echo "<br />Price: ";
echo stripslashes($row['price']);
echo "</p>";
} $result->free();
$db->close();?>
@ $db = new mysqli('localhost:8080','bookorama','bookorama123','books');
if (!$db) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
} $query = "select * from books where isbn like '%31509%'";
$result = $db->query($query); $num_results = $result->num_rows; echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars(stripslashes($row['title']));
echo "</strong><br />Author: ";
echo stripslashes($row['author']);
echo "<br />ISBN: ";
echo stripslashes($row['isbn']);
echo "<br />Price: ";
echo stripslashes($row['price']);
echo "</p>";
} $result->free();
$db->close();?>
ini_set("display_errors", 1);//加上这两行,设置PHP报错级别为输出所有错误信息
$db = new mysqli('localhost:8080','bookorama','bookorama123','books'); //去掉@符号,看有没有成功创建数据库连接另外,如果books表的数据量非常大,那按照你写的查询语句就很可能造成PHP执行超时,因为在WHERE子句中的LIKE参数如果以通配符开头的话,就不能使用索引。