2012-08-11 107 views
5
$order = new Application_Model_DbTable_Order(); 

$orderno = $order->select() 
->from($order, 'orderno') 
->where('memberid = ?', $userid) 
->order('orderno DESC') 
->limit(1, 0); 

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'SELECT ordertable . orderno FROM ordertable WHERE (memberid = '30') ORDER BY orderno DESC LIMIT 1' for column 'orderno' at row 1SQLSTATE [HY000]:常規錯誤:不正確的1366整數值:

得到這個錯誤,我想知道如果有什麼錯我的代碼,因爲我已經到處找原因,但似乎並不找到任何幫助。

#SQL code for Ordertable# 
`orderno` int(5) NOT NULL AUTO_INCREMENT, 
`memberid` int(5) DEFAULT NULL, 
PRIMARY KEY (`orderno`) 

#SQL code for Item# 
`itemid` int(5) NOT NULL AUTO_INCREMENT, 
`image` varchar(100) NOT NULL, 
`itemname` varchar(30) DEFAULT NULL, 
`description` varchar(100) DEFAULT NULL, 
`itemtype` varchar(20) DEFAULT NULL, 
PRIMARY KEY (`itemid`) 

#SQL code for Orderdetail# 
`orderdetailno` int(5) NOT NULL AUTO_INCREMENT, 
`orderno` int(5) NOT NULL, 
`itemid` int(5) NOT NULL, 
`unitcost` decimal(6,2) DEFAULT NULL, 
PRIMARY KEY (`orderdetailno`), 
KEY `orderno` (`orderno`), 
KEY `itemid` (`itemid`) 

這是我的sql代碼,如果它可以幫助我使用MySQL。

$request = new Zend_Session_Namespace('cart'); 

$auth = Zend_Auth::getInstance(); 
$user = $auth->getIdentity(); 
$userid = $user->userid; 

$order = new Application_Model_DbTable_Order(); 
$itemdb = new Application_Model_DbTable_Item(); 
$orderdetail = new Application_Model_DbTable_Orderdetail(); 

$data = array ('memberid' => $userid); 
$order->insert($data); 

$orderno = $order->select() 
->from($order, 'orderno') 
->where('memberid = ?', $userid) 
->order('orderno DESC') 
->limit(1, 0); 


foreach ($request->array as $var) 
{ 
$unitprice = $itemdb->select() 
->from('$itemdb', 'unitcost') 
->where('itemid = ?', $var); 

$newArray = array('orderno' => $orderno, 
'itemid' => $var, 
'unitcost' => $unitprice,); 

$orderdetail->insert($newArray);      
} 

任何指導將非常感激。

+0

我的表:

$newArray = array('orderno' => $orderno, // <-- this becomes a SELECT statment 'itemid' => $var, 'unitcost' => $unitprice,); $orderdetail->insert($newArray); // attempting to insert a select statement 

你應該,如果你想在INSERT語句中使用它執行$orderno聲明和fetch()結果只有2行,即orderno:1 memberid:30,orderno:2 memberid:30. – 2012-08-11 21:49:31

+0

你能發佈更多相關的代碼嗎?我認爲你正在執行錯誤的查詢。 – drew010 2012-08-11 22:30:00

+0

已編輯我的代碼! – 2012-08-12 01:59:27

回答

11

https://stackoverflow.com/a/8882396/1432614,運行

SELECT @@GLOBAL.sql_mode; 
SELECT @@SESSION.sql_mode; 

如果任一包含STRICT_TRANS_TABLES,從設置中刪除。

例如:

SET @@GLOBAL.sql_mode= 'NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; 
1

你得到這個錯誤的原因是因爲你正試圖使用​​一個Zend_Db_Select對象作爲你的INSERT聲明的值。

$orderno = $order->select() 
       ->from($order, 'orderno') 
       ->where('memberid = ?', $userid) 
       ->order('orderno DESC') 
       ->limit(1, 0); 

然後是foreach循環中:

$ordernum = $orderno->query()->fetch(); 

$newArray = array('orderno' => $ordernum, 
        'itemid' => $var, 
        'unitcost' => $unitprice,); 

$orderDetail->insert($newArray); 
相關問題