5
$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. ordernoFROM ordertableWHERE (memberid = '30') ORDER BY ordernoDESC LIMIT 1' 用于第 1 行的列 'orderno'

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

#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`)

如果它有助于我使用 MySQL,这是我的 sql 代码。

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

任何指导将不胜感激。

4

2 回答 2

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';
于 2012-08-12T02:28:52.313 回答
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

如果你想在插入语句中使用它,你应该执行$orderno语句和结果:fetch()

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

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

$orderDetail->insert($newArray);
于 2012-08-12T06:14:47.507 回答