作者:誓言俱乐部 | 来源:互联网 | 2023-05-18 11:09
我已尝试在关于此主题的其他问题上发布的每个解决方案,但它们都不起作用.
我很抱歉,如果这是一个基本问题,但我是MySQLi的新手,我无法弄清楚为什么这个连接不起作用.
我的functions.php文件中有一个函数,它具有:
function cleanInput($string) {
$stripsql = $connect->real_escape_string($string);
$addslashes = addslashes($stripsql);
return $addslashes;
}
第二行是在标题中抛出该错误.
我连接到数据库,$connect
是一个工作变量.它在config.php中设置使用:
$cOnnect= new mysqli('localhost', 'shop', 'password', 'zen');
我甚至尝试在功能之前移动该线路无济于事.
一var_dump
对$connect
在functions.php文件不返回NULL,则返回有关数据库开始的数据object(mysqli)#1 (19) { ["affected_rows"]=> int(0)
,然后用大量的行继续.
1> Kevin..:
目前,$connect
超出范围,只需将其添加到参数中:
$cOnnect= new mysqli('localhost', 'shop', 'password', 'zen');
function cleanInput($connect, $string = '') {
if(!empty($string)) {
$stripsql = $connect->real_escape_string($string);
return $stripsql;
}
}
$my_string = 'your string here';
$escaped_string = cleanInput($connect, $my_string);
旁注:或者如果可以,您也可以使用预准备语句.