SQLSTATE [HY000]:常规错误:1366不正确的整数值:

时间:2012-08-11 21:43:15

标签: mysql zend-framework

$order = new Application_Model_DbTable_Order();

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

SQLSTATE [HY000]:常规错误:1366不正确的整数值:'SELECT ordertableorderno FROM ordertable WHERE(memberid = '30')ORDER BY orderno第1行的'orderno'列的DESC LIMIT 1'

出现此错误,我想知道我的代码是否有任何问题,因为我已经到处查找原因但似乎没有找到任何帮助。

#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);                    
}

非常感谢任何指导。

2 个答案:

答案 0 :(得分: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 :(得分:1)

您收到该错误的原因是您尝试在Zend_Db_Select声明中使用INSERT对象作为值。

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

然后在foreach循环中:

$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()结果:

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

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

$orderDetail->insert($newArray);