选择“0” AS 变量...与 Zend_Db_Select
我正在尝试创建一个使用以下结构的选择语句:
$db
->select()
->from(
array('i' => ...),
array('provisional', 'itemID', 'orderID'))
->columns(array("'0' AS provisionalQty", "'ballast' AS productType"))
->joinLeft(
array('o' => ...),
'i.orderID = o.orderID', array())
->joinLeft(
array('f' => ...),
'i.productID = f.fixtureID AND f.supplierID = o.supplierID', array())
->joinLeft(
array('b' => ...),
'f.lampTechnology = b.lampTechnology ' .
' AND f.lampCount = b.lampCount ' .
' AND f.ballastVoltage = b.ballastVoltage ' .
' AND b.supplierID = o.supplierID')
->where('i.orderID = ?', $oObj->orderID, Zend_Db::INT_TYPE)
->where('!i.hidden AND i.productType = ? AND !i.provisional', 'fixture')
MySQL 中的等效项看起来像这样(工作正常)...
SELECT '0' AS provisionalQty, 'ballast' AS productType, i.* FROM ... LEFT JOIN ... WHERE ...;
但是,这并不按预期工作。 $db->columns() 方法期望每个列(甚至是“伪”列)附加一个表。有什么想法吗?
-克里斯
I am trying to create a select statement that uses the following structure:
$db
->select()
->from(
array('i' => ...),
array('provisional', 'itemID', 'orderID'))
->columns(array("'0' AS provisionalQty", "'ballast' AS productType"))
->joinLeft(
array('o' => ...),
'i.orderID = o.orderID', array())
->joinLeft(
array('f' => ...),
'i.productID = f.fixtureID AND f.supplierID = o.supplierID', array())
->joinLeft(
array('b' => ...),
'f.lampTechnology = b.lampTechnology ' .
' AND f.lampCount = b.lampCount ' .
' AND f.ballastVoltage = b.ballastVoltage ' .
' AND b.supplierID = o.supplierID')
->where('i.orderID = ?', $oObj->orderID, Zend_Db::INT_TYPE)
->where('!i.hidden AND i.productType = ? AND !i.provisional', 'fixture')
The equivalent in MySQL would look something like this (which works fine)...
SELECT '0' AS provisionalQty, 'ballast' AS productType, i.* FROM ... LEFT JOIN ... WHERE ...;
This, however, does not work as expected. The $db->columns() method expects there to be a table attached to each column even the 'pseudo'-columns. Any ideas?
-Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于此类的工作方式,似乎使用字符串/数组查找特定的表,而 Zend_Db_Expr 类不需要实际的表。
Because of the way this class works, it seems that using a string/array looks for a specific table, whereas the Zend_Db_Expr class does not require an actual table.
我认为您在这里错误地使用了列选择。它应该是这样的:
只要记住列抽象与正常的 AS 语句相反,并且您不必包含“AS”。
I think you're using column select incorrectly here. It should be something like:
Just remember the columns abstraction is reverse of the normal AS statement and you shouldn't have to include "AS."
对于那些正在谷歌搜索并寻找 Zend 2 或 Laminas 解决方案的人,这里是我的代码:
For those who are googling and looking for Zend 2 or Laminas solution, here is my code: