PHP/MYSQL使用mysqli_query选择

use*_*788 -1 html php mysql mysqli

我正在努力使用我的脚本,因为切换到mysqli它将不再起作用.我检查了PHP手册,但是看不出我做错了什么,肯定是初学者的错误.

这是我的代码:

<?php

//Connect to database
include ('connection.php');

// Retrieve all the data from the table
$result = mysqli_query("SELECT * FROM gear") or die(mysqli_error()); 

echo "<table border='1'>";
echo "<tr> <th>Manufacturer</th> <th>Model</th> <th>Description</th> </tr>";
// keeps getting the next row until there are no more to get
while($gear = mysqli_fetch_array( $result )) {

// Print out the contents of each row into a table
    echo "<tr><td>"; 
    echo $gear['manu'];
    echo "</td><td>"; 
    echo $gear['model'];
    echo "</td><td>"; 
    echo $gear['desc'];
    echo "</td></tr>"; 

} 
echo "</table>";

?>
Run Code Online (Sandbox Code Playgroud)

我想知道是不是因为我正在使用另一个脚本来连接但是它抱怨我的mysqli_query所以我收到这个错误:

[Wed Jan 01 21:14:54 2014] [错误] [client :: 1] PHP警告:mysqli_error()预计在第7行的/var/www/eml/includes/query_gear.php中给出1个参数0

任何建议或意见将不胜感激.

Joh*_*nde 9

您缺少mysqli_connect()使用mysqli_*而不是mysql_*获取的资源标识符.假设你打电话给你$link:

$result = mysqli_query($link, "SELECT * FROM gear") or die(mysqli_error($link)); 
Run Code Online (Sandbox Code Playgroud)