我正在尝试将访问者的输入插入数据库。
这行得通,但是 - 这足以防止 sql 注入吗?
<?php
$db_host = "localhost";
$db_name = "db_qadenza";
$db_user = "root";
$odb = new PDO ("mysql:host=" . $db_host . ";dbname=" . $db_name, $db_user);
if(isset($_POST['Submit']))
{
$user = $_POST['user'];
$pass = $_POST['pass'];
$mail = $_POST['mail'];
$confirm_key=md5(uniqid(rand()));
$q = "INSERT INTO members (user, pass, mail, confirm_key)
VALUES(:user, :pass, :mail, :confirm_key);";
$query = $odb->prepare($q);
$results = $query->execute(array(
":user"=>$user,
":pass"=>$pass,
":mail"=>$mail,
":confirm_key"=>$confirm_key,
));
exit();
}
?>