-2
<?php
require_once 'login1.php';
$connect = new mysqli($db_hostname, $db_username, $db_password);
if ($connect -> connect_error) {
die("Unable to connect to MySQL: " . mysql_error());
}
else {
echo "connected successfully.";
}
//selecting a database
$connects= mysqli_connect("localhost", "debola" , "mypassword");
if (mysqli_connect_errno()){
echo "failed to connect to MySQL: " . mysqli_connect_error();
}
else{
echo "Database anuoluwa selected";
}
$query = "SELECT * FROM anuoluwa";
$result = mysqli_query($query);
if (!$result) die ("Database access failed: " . mysqli_error($connect));
$rows = mysqli_num_rows($result);
for ($j = 0 ; $j < $rows ; ++$j) {
echo 'Author: ' . mysql_result($result,$j,'author') . '<br>';
echo 'Title: ' . mysql_result($result,$j,'title') . '<br>';
echo 'Category: ' . mysql_result($result,$j,'category') . '<br>';
echo 'Year: ' . mysql_result($result,$j,'year') . '<br>';
echo 'ISBN: ' . mysqli_result($result,$j,'isbn') . '<br><br>';
}
?>
這是返回錯誤的部分:PHP和MySQL查詢數據庫
$query = "SELECT * FROM anuoluwa";
$result = mysqli_query($query);
if (!$result) die ("Database access failed: " . mysqli_error($connect));
$rows = mysqli_num_rows($result);"
參數要求,我無法弄清楚。
你爲什麼連接兩次?第一次連接調用應該足夠了,作爲優點,它使用適當的面向對象的接口,而不是傳統的過程接口。作爲一個優點,這將避免陷入偶然使用'mysql_result'的陷阱,這裏完全錯誤,因爲它缺少'i'。 – tadman
你的代碼在太多層次上失敗。 –
對不起,但我不明白這個問題如何保證upvote –