测试PHP连接MYSQL连接不上
总是提示这个Error:Couldnotconnecttodatabase.Pleasetryagainlater.我用的是WAMPSERVER..编写软件是EditPl...
总是提示这个Error: Could not connect to database. Please try again later.
我用的是WAMPSERVER..编写软件是EditPlus
求大神帮忙
整串代码是这样子
if(!get_magic_quotes_gpc()) {
$searchtype=addslashes($searchtype);
$searchterm=addslashes($searchterm);
}
@ $db = new mysqli('localhost', 'bookorama', 'bookorama123', 'books');
if(mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query="select * from books where ".$searchtype." like '%".$searchterm."%'";
$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=$results->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(); 展开
我用的是WAMPSERVER..编写软件是EditPlus
求大神帮忙
整串代码是这样子
if(!get_magic_quotes_gpc()) {
$searchtype=addslashes($searchtype);
$searchterm=addslashes($searchterm);
}
@ $db = new mysqli('localhost', 'bookorama', 'bookorama123', 'books');
if(mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query="select * from books where ".$searchtype." like '%".$searchterm."%'";
$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=$results->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(); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询