I have an problem with my database connection and I really dont understand what I'm supposed to do. Anyone can help me?
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;
?>