我试图从MySQL表中选择数据,但我收到以下错误消息之一:
mysql_fetch_array()期望参数1是资源,给定布尔值
要么
mysqli_fetch_array()期望参数1为mysqli_result,给定布尔值
要么
在布尔/非对象上调用成员函数fetch_array()
这是我的代码:
$username = $_POST['username'];
$password = $_POST['password'];
$result = mysql_query('SELECT * FROM Users WHERE UserName LIKE $username');
while($row = mysql_fetch_array($result)) {
echo $row['FirstName'];
}
Run Code Online (Sandbox Code Playgroud)
这同样适用于代码
$result = mysqli_query($mysqli, 'SELECT ...');
// mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
while( $row=mysqli_fetch_array($result) ) {
...
Run Code Online (Sandbox Code Playgroud)
和
$result = $mysqli->query($mysqli, 'SELECT ...');
// Call to a member function fetch_assoc() on a non-object
while( $row=$result->fetch_assoc($result) ) {
...
Run Code Online (Sandbox Code Playgroud)
和
$result = $pdo->query('SELECT ...', PDO::FETCH_ASSOC);
// Invalid …Run Code Online (Sandbox Code Playgroud) 在我的本地/开发环境中,MySQLi查询执行正常.但是,当我在我的Web主机环境中上传它时,我收到此错误:
致命错误:在...中的非对象上调用成员函数bind_param()
这是代码:
global $mysqli;
$stmt = $mysqli->prepare("SELECT id, description FROM tbl_page_answer_category WHERE cur_own_id = ?");
$stmt->bind_param('i', $cur_id);
$stmt->execute();
$stmt->bind_result($uid, $desc);
Run Code Online (Sandbox Code Playgroud)
为了检查我的查询,我试图通过控制面板phpMyAdmin执行查询,结果是OK.
挣扎着我的网页设计任务.我一直在按照教程为我的网站添加搜索功能,但我一直收到以下错误:
警告:mysqli_num_rows()要求参数1为mysqli_result,第31行的/search.php中给出布尔值
第31行是(或是)
<pre>if(mysqli_num_rows($results) >= 1)</pre>
Run Code Online (Sandbox Code Playgroud)
那是原来的错误.根据评论中的说明,我已经修改了代码:
<pre>
<?php
//capture search term and remove spaces at its both ends if the is any
$searchTerm = trim($_GET['keyword']);
//check whether the name parsed is empty
if($searchTerm == "")
{
echo "Enter the name/brand of what you're looking for.";
exit();
}
//database connection info
$host = "localhost";
$db_name = "sookehhh_shopsy_db";
$username = "sookehhh_shopsy";
$password = "xxxx";
//connecting to server and creating link to database
$link = mysqli_connect($host, $username, $password, $db_name) or die('Could not …Run Code Online (Sandbox Code Playgroud)