Short Tag – Web Development Blog

Entries for the ‘MYSQL’ Category

Mysql AES_ENCRYPT not working properly

AES_ENCRYPT() is a MySql function for encrypting sensitive data, like passwords.
Usage examples:

SELECT AES_ENCRYPT("string","secret_key");
UPDATE `users` SET `encr_password` = AES_ENCRYPT("string", "secret_key");

The encrypted string will be binary, so it cannot be stored in a regular text field or varchar in MySql.
So, in this case:

UPDATE `users` SET `encr_password` = AES_ENCRYPT("string", "secret_key");

If `encr_password` field’s type is varchar or text then [...]

Connect to multiple Mysql databases with PHP

Sometimes we need to connect to multiple databases with our PHP script. Try not to connect to too many different hosts, this can increase considerably the execution time of your script.
First, I create the 2 connection with 2 hosts:

$user1 = "";
$pass1 = "";
$db1 = "";
$host1= "";
$conn1 = mysql_connect($host1, $user1, $pass1);

$user2 = "";
$pass2 = "";
$db2 [...]