2011-05-26 43 views
0

我的代碼:插入序列化值時Snytax錯誤?

$meta_ar = array("event_id" => $event_id, "user_id" => $user_id, "dbe" => $dbe, "hbe" => $hbe, "forum_id" => 'dummy_forum'); 

     $meta_ar = serialize($meta_ar); 

     $db->query_write(" 
      INSERT INTO " . TABLE_PREFIX . "event_mod 
       (event_meta) 
      VALUES 
       (" . $meta_ar . ") 
     "); 

錯誤:

Invalid SQL: 

      INSERT INTO event_mod 
       (event_meta) 
      VALUES 


    (a:5:{s:8:"event_id";N;s:7:"user_id";s:1:"1";s:3:"dbe";i:45;s:3:"hbe";i:32;s:8:"forum_id";s:11:"dummy_forum";}); 

MySQL Error : 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 ':5:{s:8:"event_id";N;s:7:"user_id";s:1:"1";s:3:"dbe";i:45;s:3:"hbe";i:32;s:8:"fo' at line 4 
Error Number : 1064 

任何想法?

回答

2

將其更改爲使用單引號括起來的值。

當您將任何字符串傳遞給應該保存字符串值的任何列時,則必須將其包含在引號中。

$db->query_write(" 
      INSERT INTO " . TABLE_PREFIX . "event_mod 
       (event_meta) 
      VALUES 
       ('" . $meta_ar . "') 
     "); 
+0

right lol。謝謝! – Joann 2011-05-26 16:12:55

+0

@Joann:歡迎。 – 2011-05-26 16:14:00