$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
ordertable
。orderno
FROMordertable
WHERE(memberid = '30')ORDER BYorderno
第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);
}
非常感谢任何指导。
答案 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);