我想用PHP保存符号“,”和 - 在MySQL数据库中。
由于
答案 0 :(得分:1)
我没有看到问题。 使用预准备语句 - 它们永远不会将值插入到mysql查询中。你应该能够保存你想要的任何东西。
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
try {
$dbh = new PDO($dsn, $user, $password);
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?');
$sth->bindParam(1, $calories, PDO::PARAM_INT);
$sth->bindParam(2, $colour, PDO::PARAM_STR, 12);
$sth->execute();
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
首先阅读php.net手册: PDO mysql手册: http://www.php.net/manual/en/pdo.construct.php
答案 1 :(得分:1)
$str = "This contains a comma (,) and a quote (') and should break the query";
$quoted = mysql_real_escape_string($str); /// nyah nyah now it won't.