开发者

Saving Symbols in MySQL with PHP [closed]

开发者_如何学运维 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜