t.TeacherUsername = '".MysqL_real_escape_string($teacherusername)."'
我正在将我的代码更改为MysqLi,但我想知道的是为了安全,要在MysqLi中转义字符串,如下所示:
t.TeacherUsername = '".MysqLi_real_escape_string($teacherusername)."'
$username="xxx";
$password="xxx";
$database="xxx";
MysqLi_connect('localhost',$username,$password);
MysqLi_select_db($database) or die( "Unable to select database");
更新:
$username="xxx";
$password="xxx";
$database="mobile_app";
$MysqLi = new MysqLi("localhost", $username, $password, $database);
if (MysqLi_connect_errno()) {
printf("Connect Failed: %s\n", MysqLi_connect_error());
exit();
}
解决方法:
您对该功能的使用不正确.
您必须使用MysqLi_connect返回的MysqLi链接资源作为MysqLi_real_escape_string的第一个参数.
例:
$username="xxx";
$password="xxx";
$database="xxx";
$my = MysqLi_connect('localhost',$username,$password);
MysqLi_select_db($my, $database) or die( "Unable to select database");
$t->TeacherUsername = "'" . MysqLi_real_escape_string($my, $teacherusername). "'";