php 警告:mysqli_error() 需要 1 个参数,0 给定错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7605594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: mysqli_error() expects exactly 1 parameter, 0 given error
提问by Aasim Azam
I get the following error
我收到以下错误
Warning: mysqli_error() expects exactly 1 parameter, 0 given
警告:mysqli_error() 需要 1 个参数,0 给定
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?
回答by Jason
mysqli_error() needs you to pass the connection to the database as a parameter. Documentation here has some helpful examples:
mysqli_error() 需要您将连接作为参数传递给数据库。此处的文档有一些有用的示例:
http://php.net/manual/en/mysqli.error.php
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));
回答by Aasim Azam
mysqli_error
function requires $myConnection
as parameters, that's why you get the warning
mysqli_error
函数需要$myConnection
作为参数,这就是您收到警告的原因
回答by sicKo
At first, the problem is because you did't put any parameter for mysqli_error. I can see that it has been solved based on the post here. Most probably, the next problem is cause by wrong file path for the included file.. .
一开始,问题是因为你没有为mysqli_error 设置任何参数。我可以看到它已根据此处的帖子解决。很可能,下一个问题是由包含文件的错误文件路径引起的..。
Are you sure this code
你确定这个代码
$myConnection = mysqli_connect("$db_host","$db_username","$db_pass","$db_name") or die ("could not connect to mysql");
is in the 'scripts' folder and your main code file is on the same level as the script folder?
位于“脚本”文件夹中,并且您的主代码文件与脚本文件夹位于同一级别?