There is a function in Mysql AES_encrypt.
SELECT AES_encrypt( \"Hello World\", \"password\" ) AS encrypted_value
This gives the result:
There are three problems with the code you are using:
As others have mentioned, your PHP code is currently using MCRYPT_RIJNDAEL_256
whereas, as documented under AES_ENCRYPT():
Encoding with a 128-bit key length is used, but you can extend it up to 256 bits by modifying the source. We chose 128 bits because it is much faster and it is secure enough for most purposes.
As others have mentioned, you are applying base64_encode()
to convert PHP's binary result to text, whereas the MySQL result appears merely to be a hexadecimal representation of its binary result. You can either use TO_BASE64() in MySQL since v5.6.1 or else bin2hex() in PHP.
As documented under mcrypt_encrypt():
If the size of the data is not n * blocksize, the data will be padded with '\0'.
Whereas MySQL uses PKCS7 padding.
Therefore, to obtain the same results in PHP as you currently show for MySQL: