I have my mysql_* converting to mysqli, but I encounter below issue.
php class (Functions.php):
class Functions{
public static function filter($data){
$data = trim(htmlentities(strip_tags($data)));
if(get_magic_quotes_gpc())
$data = stripslashes($data);
$data = $mysqli->real_escape_string($data);
return $data;
}
}
DB connection (dbconnect.php):
$dbhost = 'localhost';
$dbuser = 'xxxxxx';
$dbpass = 'xxxxxx';
$dbname = 'xxxxxx';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if(mysqli_connect_errno()){
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
I include above file in header.php like
include('inc/dbconnect.php');
include('inc/Functions.php');
I had my page call the class function like:
$params = Functions::filter($_GET['param']);
I got this error when I load the page:
Fatal error: Call to a member function real_escape_string() on a non-object in C:\xampp\htdocs\site\inc\functions.php on line XX
Isn't I already created an object for mysqli in dbconnect.php? why it show this error? it happen to all related mysqli in Functions.php.
Please advise, many thanks.
global $mysqli;to your method or use$GLOBALS['mysqli']instead. But I suggest passing the object as an function argument