本文介紹了警告:mysqli_error() 需要 1 個參數,0 給定錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我收到以下錯誤
<塊引用>警告:mysqli_error() 需要 1 個參數,0 給定
問題在于這行代碼:
$query = mysqli_query($myConnection, $sqlCommand) 要么死 (mysqli_error());
整個代碼是
session_start();require_once "scripts/connect_to_mysql2.php";//構建主導航菜單并在此處收集頁面數據$sqlCommand = "SELECT id, linklabel FROM pages ORDER BY pageorder ASC";$query = mysqli_query($myConnection, $sqlCommand) 要么死 (mysqli_error());$menuDisplay = '';而 ($row = mysqli_fetch_array($query)) {$pid = $row["id"];$linklabel = $row["linklabel"];$menuDisplay .= '<a href="index.php?pid='. $pid .'">'.$鏈接標簽.'</a><br/>';}mysqli_free_result($query);
包含的文件有以下一行
$myConnection = mysqli_connect("$db_host","$db_username","$db_pass","$db_name") 要么死("無法連接到mysql");參考 $myConnection,為什么會出現此錯誤?
解決方案
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 給定錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!