每次出现此错误时,都是database.php
代码:
注意:未定义的变量:dbConn in 第15行的C:\ xampp \ htdocs \ couriermanagement \ database.php
警告:mysqli_query()期望参数1为mysqli,null给定 在第15行的C:\ xampp \ htdocs \ couriermanagement \ database.php
警告:mysqli_error()正好需要1个参数,给出0 第15行的C:\ xampp \ htdocs \ couriermanagement \ database.php
<?php
// database connection config
$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = '';
$dbName = 'courier_db';
$dbConn = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName) or die ('MySQL
connect failed. ' . mysqli_error($dbConn));
//mysqli_select_db($dbConn ,$dbName) or die('Cannot select database. ' .
mysqli_error($dbConn));//
function dbQuery($sql)
{
$result = mysqli_query($dbConn,$sql) or die(mysqli_error());
return $result;
}
function dbAffectedRows()
{
global $dbConn;
return mysqli_affected_rows($dbConn);
}
function dbFetchArray($result, $resultType = MYSQL_NUM) {
return mysqli_fetch_array($result, $resultType);
}
function dbFetchAssoc($result)
{
return mysqli_fetch_assoc($result);
}
function dbFetchRow($result)
{
return mysqli_fetch_row($result);
}
function dbFreeResult($result)
{
return mysqli_free_result($result);
}
function dbNumRows($result)
{
return mysqli_num_rows($result);
}
function dbSelect($dbName)
{
return mysqli_select_db($dbName);
}
function dbInsertId()
{
return mysqli_insert_id();
}
?>
答案 0 :(得分:1)
缺少“链接”我认为你从mysql升级到mysqli
它应该是这样的:
$dbConn = mysqli_connect("localhost", "my_user", "my_password", "world");
mysqli_query($dbConn, "SELECT * FROM test");
读:
http://php.net/manual/en/mysqli.query.php
程序风格下的
答案 1 :(得分:0)
您应该添加
$con=mysqli_connect("hostmane","userename","password","db_name");
在行之前
$result = mysqli_query($dbConn,$sql) or die(mysqli_error());