I am trying to use AES_DECRYPT in MySQL to decrypt a successfully encrypted SSN. In the output I get the word “Array” instead of the actual data from that field. My PHP and MySQL knowledge is a bit rusty, so I’m sure it’s something silly I overlooked. Any help would be appreciated.
OUTPUT:
verify_name other_names ssn dob
: test : test : Array : test
CODE:
$key="88b871WZ3SntWK67rN3l2J1SvMqsOjyk";
$SQLstring = "SELECT * FROM applications";
$QueryResult = @mysql_query($SQLstring, $conn) or die("Query Problem - "
. mysql_error($conn) . " - Error Number - "
. mysql_errno($conn));
echo "verify_name other_names ssn dob";
$num_result = mysql_num_rows($QueryResult);
for ($i = 0; $i < $num_result; $i++)
{
$row = mysql_fetch_array($QueryResult);
$SQLstring2 = "SELECT AES_DECRYPT(ssn,'$key') FROM applications WHERE name='" . $row["name"] . "'";
$QueryResult2 = @mysql_query($SQLstring2, $conn) or die("Query Problem - "
. mysql_error($conn) . " - Error Number - "
. mysql_errno($conn));
$num_result2 = mysql_num_rows($QueryResult2);
for ($j = 0; $j < $num_result; $j++){
$ssndecrypt = mysql_fetch_array($QueryResult2);
echo $ssndecrypt[0];
}
echo $row["verify_name"];
echo $row["other_names"];
echo $ssndecrypt;
echo $row["dob"];
It’s because you’re fetching the result as an array.
It’s echoing
Arraybecause you never reassign the$ssndecryptvariable.The core of the problem, however, seems to be that you’re needlessly complicating your queries. There’s no reason to query the table twice when you can just do:
This simplifies the code quite a bit:
Ideally, though, you should be using PDO instead of the
mysql_*functions: