我在php函數中擁有這些sql語句,並且已經傳遞了所有需要的變量。我在查詢中有2個插入語句。他們將數據插入到同一個表中,第一個插入用於主要服務,第二個插入如果在我的網站中使用附加服務。SQL不會從php中獲取所有傳遞的變量
SQL以某種方式獲取$ userid和$ item_label的值,第一個插入工作得很好。除非將$ userid和$ item_label更改爲靜態值,例如'123','122',否則第二次插入將不起作用。 (所以基本上,如果我離開他們作爲:userid
,:item_label
,SQL不會值插入到表)
但是其他的重疊變量,如$filename
,同時使用INSERT語句不會引起任何問題。
而$userid
不是目標表的索引或任何東西。所以,請幫助。這裏是代碼
function add_writing_editing_to_table($userid, $item_label, $basic_writing_service_id, $basic_writing_price, $editing_service_subcategory, $editing_service_id, $editing_serivce_price, $filename, $new_filename){
global $db;
$query = "INSERT INTO op_cart
(service_category, userid, item_label, service_subcategory, service_id, is_addon, unit, total_price, filename, new_filename, checkout)
VALUES
('writing', :userid, :item_label, 'basic_writing', :basic_writing_service_id, '0', '1', :basic_writing_price, :filename, :new_filename, '0'),
('editing', :userid, :item_label, :editing_service_subcategory, :editing_service_id, '1', '1', :editing_serivce_price, :filename, :new_filename, '0');";
$statement = $db->prepare($query);
$statement->bindValue(':userid', $userid);
$statement->bindValue(':item_label', $item_label);
$statement->bindValue(':basic_writing_service_id', $basic_writing_service_id);
$statement->bindValue(':basic_writing_price', $basic_writing_price);
$statement->bindValue(':filename', $filename);
$statement->bindValue(':new_filename', $new_filename);
$statement->bindValue(':editing_service_subcategory', $editing_service_subcategory);
$statement->bindValue(':editing_service_id', $editing_service_id);
$statement->bindValue(':editing_serivce_price', $editing_serivce_price);
$statement->execute();
$statement->closeCursor();
}
可能重複http://stackoverflow.com/questions/15069962/php-pdo-insert-batch - 多行佔位符) – Ghost 2014-10-01 00:33:45
好吧,如果userid和item_label沒有作爲變量傳遞到值的第二行,那麼可以實現多行插入....所以,我只想知道sql爲什麼會這樣做,如何解決它 – Bubble 2014-10-01 01:17:53
我以某種方式設法解決了改變錯誤異常和傳遞值作爲字符串(以及大量的字符串函數),誘使sql認爲這兩個變量是靜態值... arr..it工作..但它是真的很傻=。= – Bubble 2014-10-01 03:20:46