Saving Symbols in MySQL with PHP [closed]
i want to save the Symbols “, ” and — in a MySQL Database with PHP.
Thanks
I don't see the problem. Use prepared statements - they never interpolate values into mysql query. You should be able to save anything you want.
$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();
}
always read php.net manual first: PDO mysql manual: http://www.php.net/manual/en/pdo.construct.php
$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.
精彩评论