I'm trying to make a unified function for a PDO prepare UPDATE statement. But I am doing something wrong. Help would be very much appreciated.
I'm passing an array and an email to a function:
function refreshUserData($items,$email)
{
global $pdo;
$keys = array_keys($items);
$keys = '('. implode(",", $keys) . ')';
$values = array_values($items);
$values = '(\''. implode("','", $values) . '\')';
$query = $pdo->prepare("UPDATE users SET $keys VALUES $values WHERE email=?");
$query->bindValue(1,$email);
$query->execute();
}
But I am doing something wrong because when I try to run a function Uncaught exception
This is my first attempt at doing this so don't know what to do.
Array being passed through:
Array ( [google_id] => 11111111111111 [emal] => email@gmail.com [first_name] => First [last_name] => Last [profile_url] => https://plus.google.com/+FirstLast )
And after implodes:
(google_id,emal,first_name,last_name,profile_url)
('11111111111111','email@gmail.com','First','Last','https://plus.google.com/+FirstLast')