如何使用7.0.7在mysql数据库中插入特殊字符


how to insert special characters in mysql DB using 7.0.7

mysql_real_escape_string()在PHP 5.5.0中被弃用,在PHP 7.0.0中被删除,那么我能用PHP 7.0.7在mysql DB中插入特殊字符吗?

使用addslashes而不是mysql_real_escape_string()

您可以使用PDO插入特殊字符。让我们看看示例:

<?php
$conn = new PDO('mysql:host=localhost;dbname=form', $username, $password);
/* Complex string */
$string = "Co'mpl''ex '"st''"ring";
print "Unquoted string: $string'n";
print "Quoted string: " . $conn->quote($string) . "'n";
?>