I got a problem with real_escape_string
code:
function mysql_escape($str){
echo '<pre>';
var_dump(self::$link);
echo '</pre>';
return self::$link->real_escape_string($str);
}
output:
object(mysqli)#1 (17) {
["affected_rows"]=>
NULL
["client_info"]=>
NULL
["client_version"]=>
int(50051)
["connect_errno"]=>
int(0)
["connect_error"]=>
NULL
["errno"]=>
NULL
["error"]=>
NULL
["field_count"]=>
NULL
["host_info"]=>
NULL
["info"]=>
NULL
["insert_id"]=>
NULL
["server_info"]=>
NULL
["server_version"]=>
NULL
["sqlstate"]=>
NULL
["protocol_version"]=>
NULL
["thread_id"]=>
NULL
["warning_count"]=>
NULL
}
Warning: mysqli::real_escape_string() [mysqli.real-escape-string]: Couldn't fetch mysqli in /usr/www/users/.../class/class.Data.php on line 188
Is the connection opened correctly? I assume you've got something like
self::$link = new mysqli(...);
If it can't connect, it doesn't return false
, but an object, so in any case, your conditional always evaluates to true
:
if (self::$link)
{
echo "I'm always here!"
}
Try mysqli_connect_error()
or self::$link->connect_error()
(depending on your php version) as stated in mysqli::__construct
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.