在php mysql中存储转义字符

时间:2015-04-21 08:46:24

标签: php mysql

我需要在php mysql数据库中存储一些密码。问题是我的密码列表有一些转义字符。如何保存这些记录?

以下是代码,我正在尝试添加。

$pwd='\/'vm';
Insert into passwords(password) values ('$pwd') ;

由于此表处理密码,除了存储转义chrachets之外,我没有任何其他选项。

提前致谢!

2 个答案:

答案 0 :(得分:1)

假设PDO扩展名和PHP 5.5+,可以说现在存储密码的最佳方式是:

//assuming you're retrieving the password from a user-POSTed form under SSL
$pwd = password_hash($_POST['pwd']); 

//prepare the statement
$stmt = $pdo->prepare("INSERT INTO passwords (passwords.password) VALUES (:pwd)");
$stmt->bindParam(':pwd', $pwd, PDO::PARAM_STR);

//execute (returns boolean success state)
$success = $stmt->execute();

答案 1 :(得分:-1)

$pwd='\/'vm';
$pwd = mysqli_real_escape_string($pwd);
$query = "Insert into passwords(password) values ('$pwd')" ;
相关问题