我刚刚从头开始编写自己的 php 注册脚本,由于我是新手,所以我想问一下我使用的方法是否可以防止 sql 注入?
这是我如何与我的 sql 数据库交换数据的示例:
public function StoreUser($name, $email, $password, $devid) {
$mysqli = new mysqli("host", "user", "pass", "data");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$unique_id = uniqid('', true);
$hash = $this->hashSSHA($password);
$add_user = $mysqli->prepare("INSERT INTO `users` SET `unique_id`=?, `name`=?, `email`=?, `encrypted_password`=?, `salt`=?, `devid`=?, `created_at`=?");
$add_user->bind_param("sssssss",$unique_id,$name,$email,$hash["encrypted"],$hash["salt"],$devid,date("H:i:s"));
if ($add_user->execute()) {
$add_user->close();
$mysqli->close();
return true;
}
else {
$add_user->close();
$mysqli->close();
return false;
}
}