I use this function to update a table.
It works correctly in xamp and local but on the server it returns this error:
Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ': WHERE
id
=1' at line
function update($sTable, $aValues = array(),$key,$debug = 0){
global $pdo;
unset($aValues['edit']);
unset($aValues['update']);
if (!empty($aValues) && !empty($sTable)){
# validation of table / columns nam
$aColumns = array_map('mysql_real_escape_string',array_keys($aValues));
$aElements = array();
foreach ($aColumns as $sColumn){
$aElements[] = "`$sColumn`= :$sColumn";
} // foreach
$oPDOStatement = $pdo->prepare("UPDATE $sTable SET " . implode(',', $aElements)." WHERE `id`=$key");
$oPDOStatement->execute($aValues);
if($debug==1) print_r($oPDOStatement->errorInfo());
}
}