警告:mysqli_error()恰好需要1个参数,给定0个错误 [英] Warning: mysqli_error() expects exactly 1 parameter, 0 given error
本文介绍了警告:mysqli_error()恰好需要1个参数,给定0个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下错误
警告:mysqli_error()恰好需要1个参数,给定0个
问题出在这行代码上:
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
整个代码是
session_start();
require_once "scripts/connect_to_mysql2.php";
//Build Main Navigation menu and gather page data here
$sqlCommand = "SELECT id, linklabel FROM pages ORDER BY pageorder ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$menuDisplay = '';
while ($row = mysqli_fetch_array($query)) {
$pid = $row["id"];
$linklabel = $row["linklabel"];
$menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />';
}
mysqli_free_result($query);
包含的文件包含以下行
$myConnection = mysqli_connect("$db_host","$db_username","$db_pass","$db_name") or die ("could not connect to mysql"); with reference to $myConnection, why do I get this error?
解决方案
mysqli_error()需要您将连接作为参数传递给数据库.这里的文档提供了一些有用的示例:
http://php.net/manual/en/mysqli.error.php >
尝试像这样更改问题线,您的身体就会保持良好状态:
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection));
I get the following error
Warning: mysqli_error() expects exactly 1 parameter, 0 given
The problem is with this line of the code:
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
The whole code is
session_start();
require_once "scripts/connect_to_mysql2.php";
//Build Main Navigation menu and gather page data here
$sqlCommand = "SELECT id, linklabel FROM pages ORDER BY pageorder ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$menuDisplay = '';
while ($row = mysqli_fetch_array($query)) {
$pid = $row["id"];
$linklabel = $row["linklabel"];
$menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />';
}
mysqli_free_result($query);
The included file has the following line
$myConnection = mysqli_connect("$db_host","$db_username","$db_pass","$db_name") or die ("could not connect to mysql"); with reference to $myConnection, why do I get this error?
解决方案
mysqli_error() needs you to pass the connection to the database as a parameter. Documentation here has some helpful examples:
http://php.net/manual/en/mysqli.error.php
Try altering your problem line like so and you should be in good shape:
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection));
这篇关于警告:mysqli_error()恰好需要1个参数,给定0个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文