PHP / MYSQL使用mysqli_query进行选择 [英] PHP / MYSQL select using mysqli_query
问题描述
我正在努力处理我的脚本,并且因为切换到mysqli而不再工作。我检查了PHP手册,但是看不到我做错了什么,肯定是一个初学者的错误。
以下是我的代码:
<?php
// Connect到数据库
include('connection.php');
//检索表中的所有数据
$ result = mysqli_query(SELECT * FROM gear)或die(mysqli_error());
echo< table border ='1'>;
echo< tr>制造商< th>模型< / th>< th>描述< / th>< / tr>;
//继续获取下一行,直到没有更多的元素获得
时($ gear = mysqli_fetch_array($ result)){
//打印出每个元素的内容排成一张表
echo< tr>< td>;
echo $ gear ['manu'];
echo< / td>< td>;
echo $ gear ['model'];
echo< / td>< td>;
echo $ gear ['desc'];
回显< / td>< / tr>;
}
echo< / table>;
?>
我想知道是否因为我正在使用另一个脚本进行连接,但它是抱怨我的mysqli_query,所以我得到这个错误:
$ b
[Wed Jan 01 21:14:54 2014] [error] [client: :1] PHP警告:mysqli_error()期望只有1个参数,0在第7行的/var/www/eml/includes/query_gear.php中给出
任何建议或建议,将不胜感激。
c> mysqli_connect(),这是mysqli_ *所必需的,而不是mysql_ *所需的。假设你叫你 $ link
:
$ result = mysqli_query($链接,选择*从齿轮)或死(mysqli_error($链接));
I am struggling with my script and since switching to mysqli it will no longer work.I have checked the PHP manual but just cannot see what I am doing wrong, surely a beginners mistake.
Here is my code:
<?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>";
?>
I am wondering if it is because of the fact that I am using another script to connect but it is complaining about my mysqli_query so I am getting this error:
[Wed Jan 01 21:14:54 2014] [error] [client ::1] PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /var/www/eml/includes/query_gear.php on line 7
Any advice or suggestions would be appreciated.
You are missing your resource identifier obtained with mysqli_connect()
which is required with mysqli_* and not with mysql_*. Assuming you called yours $link
:
$result = mysqli_query($link, "SELECT * FROM gear") or die(mysqli_error($link));
这篇关于PHP / MYSQL使用mysqli_query进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!