當我從PHP MyAdmin運行SQL查詢時,它會正確插入該行;當我從PHP運行它時,它不會。mySQL查詢不能從PHP工作,但在PHPMyAdmin中工作
我將爲您提供每個文本;他們是相同的,但鑑於我可能錯過了某些東西,我不想假設沒有任何區別。
在PHP中:
在PHP MyAdmin$orderSend = "SET @typeSQL := (SELECT `typeID` FROM `ArbuckleType` WHERE `typeName` = 'A la Carte');
SET @groupSQL:= (SELECT `groupID` FROM `ArbuckleGroup` WHERE (`groupName` = 'Nigiri' AND `typeID` = @typeSQL));
SET @itemSQL:=(SELECT `itemID` FROM `ArbuckleItem` WHERE (`itemName` = 'Salmon' AND `groupID` = @groupSQL));
INSERT INTO `ArbuckleOrderDetails` VALUES('', '$orderID', @typeSQL,@groupSQL, @itemSQL, '$quantity', '$spicy')";
mysql_query($orderSend);
現在:
SET @type := (SELECT `typeID` FROM `ArbuckleType` WHERE `typeName` = 'A la Carte');# MySQL returned an empty result set (i.e. zero rows).
SET @group:= (SELECT `groupID` FROM `ArbuckleGroup` WHERE (`groupName` = 'Nigiri' AND `typeID` = @type));# MySQL returned an empty result set (i.e. zero rows).
SET @item:=(SELECT `itemID` FROM `ArbuckleItem` WHERE (`itemName` = 'Salmon' AND `groupID` = @group));# MySQL returned an empty result set (i.e. zero rows).
INSERT INTO `ArbuckleOrderDetails` VALUES('', '$orderID', @type,@group, @item, '$quantity', '$spicy')
注:我跑的PHP查詢無SET調用(3線設置變量)和它的工作;但我無法弄清楚這些行中的語法錯誤。還運行mysql_error,它聲明有一個語法錯誤 - 然後讓我看看手冊。非常有幫助,MySQL。
我不會使用mysql_ *函數。他們已被棄用,並有充分的理由。閱讀更多在:http://www.php.net/manual/en/mysqlinfo.api.choosing.php –