警告:mysqli_real_escape_string()恰好需要2个参数,其中1个给定...致命错误:在null中调用成员函数query() [英] Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in... Fatal error: Call to a member function query() on null in
问题描述
我的数据库连接有问题,我真的不明白我该怎么做.有人可以帮助我吗?
I have an problem with my database connection and I really dont understand what I'm supposed to do. Anyone can help me?
警告:mysqli_real_escape_string()恰好需要2个参数,即1 在/customers/f/4/7/zebratv.se/httpd.www/classes/db.php中给出 47致命错误:在 /customers/f/4/7/zebratv.se/httpd.www/classes/db.php,第61行
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /customers/f/4/7/zebratv.se/httpd.www/classes/db.php on line 47 Fatal error: Call to a member function query() on null in /customers/f/4/7/zebratv.se/httpd.www/classes/db.php on line 61
<?php
class db
{
public function __construct()
{
global $CONFIG;
$mysqli = $CONFIG->get("database");
$this->dbconn($mysqli["host"], $mysqli["username"], $mysqli["password"], $mysqli["database"]);
}
private function dbconn($mysqli_host, $mysqli_user, $mysqli_pass, $mysqli_db)
{
if (!($conn = new mysqli($mysqli_host, $mysqli_user, $mysqli_pass)))
{
switch (mysqli_errno($conn))
{
case 1040:
case 2002:
if ($_SERVER[REQUEST_METHOD] == "GET")
die("<html><head><meta http-equiv=refresh content=\"5 $_SERVER[REQUEST_URI]\"></head><body><table border=0 width=100% height=100%><tr><td><h3 align=center>The server load is very high at the moment. Retrying, please wait...</h3></td></tr></table></body></html>");
else
die("Too many users. Please press the Refresh button in your browser to retry.");
default:
die("[" . mysqli_errno($conn) . "] dbconn: mysqli_connect: " . mysqli_error($conn));
}
}
mysqli_select_db($conn, $mysqli_db)
or die('dbconn: mysqli_select_db: ' + mysqli_error($conn));
usercontrol::userlogin();
}
public function sql_query($query)
{
@++$_SESSION['totalqueries'];
return $conn->query($query);
}
public function sanitize($var)
{
return($this->sqlesc((htmlspecialchars($var))));
}
function sqlesc($x) {
return "'".mysqli_real_escape_string($x)."'";
}
public function sqlerr($file = '', $line = '')
{
print("<table border=0 bgcolor=blue align=left cellspacing=0 cellpadding=10 style='background: blue'>" .
"<tr><td class=embedded><font color=white><h1>SQL Error</h1>\n" .
"<b>" . mysqli_error() . ($file != '' && $line != '' ? "<p>in $file, line $line</p>" : "") . "</b></font></td></tr></table>");
die;
}
public function get_row_count($table, $suffix = "")
{
if ($suffix)
$suffix = " $suffix";
$query = "SELECT COUNT(*) FROM ".$table."".$suffix;
$r = $conn->query($query) or die(mysqli_error());
$a = $conn->fetch_row($r) or die(mysqli_error());
return $a[0];
}
}
$DB = new db;
?>
推荐答案
mysqli_real_escape_string 函数需要数据库链接作为第一个参数.所以改变
mysqli_real_escape_string function requires the database link as the first argument. So change
mysqli_real_escape_string($x)
使用
mysqli_real_escape_string($conn, $x)
这篇关于警告:mysqli_real_escape_string()恰好需要2个参数,其中1个给定...致命错误:在null中调用成员函数query()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!