gpt4 book ai didi

php - 警告 : mysqli_error() expects exactly 1 parameter, 0 给定错误

转载 作者:IT老高 更新时间:2023-10-29 00:05:24 25 4
gpt4 key购买 nike

我得到以下错误

Warning: mysqli_error() expects exactly 1 parameter, 0 given

问题在于这行代码:

$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)); 

关于php - 警告 : mysqli_error() expects exactly 1 parameter, 0 给定错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7605594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com