Friday, 23 August 2013

Syntax error : the right syntax to use near '' at line 1 mysql

Syntax error : the right syntax to use near '' at line 1 mysql

i think im getting retarded. I made a function for my dao that generates
an insert query, and this simple query gives a syntax error. I even
checked up mysql reserved words and added those into the funtion, so when
they occur they get backticks.
public static function buildInsert(&$db, $oTable ){
$db = db::get();
$q = "INSERT INTO ".$oTable->table." ";
$class = get_class($oTable);
$q .= '(';
$i = 0;
foreach($class::$arTableFields as $key => $value){
$i++;
if($oTable->primaryKey == $class::$arTableFields[$key])
continue;
if(empty($oTable->arAssoc[$key]))
continue;
if(in_array($key, db::$reservedMysqlWords))
$key = "`".$key."`";
$q .= $key;
$q .= ($i == sizeof($class::$arTableFields) ? '' : ',');
}
$q.= ')';
$q.= ' VALUES (';
$i = 0;
foreach($class::$arTableFields as $key => $value){
$i++;
if($oTable->primaryKey == $class::$arTableFields[$key])
continue;
if(empty($oTable->arAssoc[$key]))
continue;
$q .= (!empty($oTable->arAssoc[$key]) ?
(is_numeric($oTable->arAssoc[$key]) ? $oTable->arAssoc[$key] :
"'".$db->real_escape_string($oTable->arAssoc[$key])."'" ) : "'
'");
$q .= ($i == sizeof($class::$arTableFields) ? '' : ',');
}
$q.= ') ';
return $q;
}
Now when i throw in a filled table object it generates the following string:
INSERT INTO customer
(firstname,lastname,email,password,joindate,newsletter,banknumber,street,`number`,zip,country,city,discountpoints)
VALUES ('david','errrr','ddd@asdde.com','#$Dasd21143','0000-00-00
00:00:00',1,32,'blabla',138,'3153BB','HongKong','Paris',6)
Which results into Error in query: 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 '' at line 1
Someone PLEASE help me out! Im going nuts :(

No comments:

Post a Comment