DB Security
First you need to ask yourself: "Why are you encrypting the data in the database?".
The reason is that the database may fall into the wrong hands.
For this reason, you cannot save the key in the database itself.
You must assume that all the data in the database is known to the attacker.
Therefore, the only answer is the presence of a key outside the database.
I would advise salting the key using the data on the same line as the article so that the attacker could not use the rainbow table for all the articles.
pseudocode for select statement: SELECT AES_DECRYPT(article, CONCAT(salt, '$secret_key')) FROM articles WHERE id = '123'
PHP Security
Please note that listing AES encryption key in PHP source code will also be an error.
He will have to live only in the memory of the computer, which must also be safe.
The option is to read it from a remote computer (make an encrypted transmission), which is safe (a data center with protection), or have a senior official key when starting the program.
How to avoid MySQL ECB hole
If you need this to be truly secure, you will need to do encryption in php.
See this article to find out why MySQL (which uses ECB mode) has a problem: http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
pseudo code
<?pseudophp $secretmessage = $_GET['secret_message_from_user']; $randomprefix = hash('sha512',$timestampinmilliseconds); $secretmessage = $randomprefix."@@@@".$secretmessage;
Johan
source share