nkcmr
nkcmr

Reputation: 11010

help with mysql AES_ENCRYPT

I have prepared a query but it keeps throwing errors. Here is my query:

$query = "INSERT INTO encryption_tests (values) VALUES (AES_ENCRYPT('pass', 'password'))";

I have successfully connected to the server and selected a database. Here is the mysql_error():

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 'values) VALUES (AES_ENCRYPT('pass', 'password'))' at line 1

Can anybody see anything I'm not seeing? Thanks for your help and if you have any questions, do ask.

Upvotes: 1

Views: 564

Answers (1)

Treffynnon
Treffynnon

Reputation: 21563

values is a MySQL reserved word. You need to escape it with backticks like so:

$query = "INSERT INTO `encryption_tests` (`values`) VALUES (AES_ENCRYPT('pass', 'password'))";

Although my personal preference is to write queries this way as I find them much easier to read:

INSERT INTO `encryption_tests`
SET `values` = AES_ENCRYPT('pass', 'password')

Upvotes: 4

Related Questions