php - Syntax error : the right syntax to use near '' at line 1 mysql -
i made function dao generates insert query, , simple query gives syntax error.
i checked mysql reserved words , added function, when occur backticks.
public static function buildinsert(&$db, $otable) { $db = db::get(); $q = "insert " . $otable->table . " "; $class = get_class($otable); $q .= '('; $i = 0; foreach ($class::$artablefields $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 $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 throw in filled table object generates following string:
insert 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 `error in query:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 1`
Comments
Post a Comment