mysql escaping single and double quotes

我的未来我决定 提交于 2019-12-06 12:18:53

mysql_real_escape_string is made for just this.

PHP: mysql_real_escape_string

$insert = "INSERT INTO wp_posts ('body','title') VALUES ('".mysql_real_escape_string($row['body'])."', '".mysql_real_escape_string($row['row'])."')";

The other option is to use mysqli and prepared statements

$stmt = $this->db->prepare("insert into table (id,name,longstring) values (?,?,?));
$stmt->bind_param('iss',$row["id"],$row["name"],$row["body"]);
$stmt->execute();

mysqli will bind the assigned parameters to the ? in the prepared statement as an integer (i) or a string (s).

The sanest approach is to use bound parameters. Bobby Tables has examples.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!