This question already has an answer here:
- Mysql syntax seems correct 3 answers
I have query function in model:
public function query($qry, $params = array()) {
try {
$pdo = $this->prepare($qry);
$pdo->execute($params);
return $pdo->fetchAll(PDO::FETCH_OBJ);
}
catch (PDOException $e) {
return '<div class="error message">' . $e->getMessage() . '</div>';
}
}
Where I want to INSERT some data to table with this code:
$email = $_POST['email'];
$key = $this->key_generator();
$password = sha1($_POST['password']);
$qry = "
INSERT INTO users
(email, password, key)
VALUES (:email, :password, :key)
";
$params = array(
':email' => $email,
':password' => $password,
':key' => $key
);
$result = $this->query($qry, $params);
Note: this is only testing code ...
I catch exception:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key) VALUES
I can't figure out where is syntax error near key)
.
</div>