我寫了一個簡單的php代碼來顯示mySql表中的數據。 當我使用「mysql_connect」,「mysql_select_db」時,這個工作正常,但當我使用 「mysqli_connect」,「mysqli_select_db」時不工作。任何人都可以請點亮它。mysqli不工作
我是一個非常初級的Web開發人員。
這是我寫的代碼:
<?php
$con = mysqli_connect("localhost","root","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db=mysqli_select_db("database_name",$con) or die("Could not select DB");
if (!$db)
{
die('no database connected');
}
$data = mysql_query("SELECT * FROM categories")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array($data))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['parentId'] . "</td> ";
Print "<th>ID:</th> <td>".$info['title'] . "</td> </tr>";
}
Print "</table>";
?>
但是,如果我取代「mysqli的」支持「mysql」,那麼它的工作。
混合mysqli_connect和mysqli_select_db用的mysql_query是你的問題....是關於你正在使用的庫一致......你需要使用mysqli的查詢方法 – 2013-02-08 23:09:25