我正在尝试使用Zend_Db_Select执行查询。这是我的代码:
$db = $this->db;
$select = $this->db->select(false)
->from('invoice',$data1)
->join('partner_settings', $db->quoteInto('partner_settings.clientid = ?', $clientid), array()) //'toggle_value'))
->join('partner_info', $db->quoteInto('partner_info.rowid = partner_settings.partnerinfoid', array())) //'type', 'shipper_name' => 'partner_info.name')))
->join('partner_shipping', $db->quoteInto('partner_shipping.partnersettingsid = partner_settings.rowid', array())) //'default_method_id')))
->join('partner_ship_methods', $db->quoteInto('partner_ship_methods.rowid = partner_shipping.default_method_id'), array()) //'shipping_method' => 'name'))
->where('storeid IN (?)',$inputid)
->where('partner_info.type = ?', 'shipping')
->where('partner_settings.toggle_value = ?', 'on')
->order(array('datetime_cre DESC'));
$ data1是一个包含以下值的数组:
Array
(
[0] => invoice_date AS inv_invoice_date
[1] => invoice_id AS inv_invoice_id
[2] => name AS inv_name
[3] => ups_track AS inv_ups_track
[4] => shipping_pdf AS inv_shipping_pdf
[5] => invoice_pdf AS inv_invoice_pdf
[6] => alert AS inv_alert
[7] => invoice_date AS inv_invoice_date
[8] => invoice_id AS inv_invoice_id
[9] => name AS inv_name
[10] => subtotal AS inv_subtotal
[11] => tax_inclusive AS inv_tax_inclusive
[12] => total AS inv_total
[13] => shipping_pdf AS inv_shipping_pdf
[14] => invoice_pdf AS inv_invoice_pdf
[15] => alert AS inv_alert
[16] => rowid
[17] => partner_info.name AS shipper_name
[18] => partner_ship_methods.name AS shipping_method
)
生成的MYSQL查询如下所示:
SELECT `invoice`.`invoice_date` AS `inv_invoice_date`, `invoice`.`invoice_id` AS `inv_invoice_id`, `invoice`.`name` AS `inv_name`, `invoice`.`ups_track` AS `inv_ups_track`, `invoice`.`shipping_pdf` AS `inv_shipping_pdf`, `invoice`.`invoice_pdf` AS `inv_invoice_pdf`, `invoice`.`alert` AS `inv_alert`, `invoice`.`invoice_date` AS `inv_invoice_date`, `invoice`.`invoice_id` AS `inv_invoice_id`, `invoice`.`name` AS `inv_name`, `invoice`.`subtotal` AS `inv_subtotal`, `invoice`.`tax_inclusive` AS `inv_tax_inclusive`, `invoice`.`total` AS `inv_total`, `invoice`.`shipping_pdf` AS `inv_shipping_pdf`, `invoice`.`invoice_pdf` AS `inv_invoice_pdf`, `invoice`.`alert` AS `inv_alert`, `invoice`.`rowid`, `partner_info`.`name` AS `shipper_name`, `partner_ship_methods`.`name` AS `shipping_method`, `partner_info`.*, `partner_shipping`.* FROM `invoice`
INNER JOIN `partner_settings` ON partner_settings.clientid = '33'
INNER JOIN `partner_info` ON partner_info.rowid = partner_settings.partnerinfoid
INNER JOIN `partner_shipping` ON partner_shipping.partnersettingsid = partner_settings.rowid
INNER JOIN `partner_ship_methods` ON partner_ship_methods.rowid = partner_shipping.default_method_id WHERE (storeid IN ('43')) AND (partner_info.type = 'shipping') AND (partner_settings.toggle_value = 'on') ORDER BY `datetime_cre` DESC
我最大的问题是SELECT columns子句,其中包括:partner_info
。*,partner_shipping
。*我不想包含这些表中的所有列。我已将join()列参数设置为空数组(),但它没有帮助。
有没有人找到解决这个问题的方法?我一直在徒劳地寻找。
答案 0 :(得分:1)
您没有将columns参数设置为空数组,而是将数组作为第二个参数传递给quoteInto()
。你有:
->join('partner_info', $db->quoteInto('partner_info.rowid = partner_settings.partnerinfoid', array()))
quoteInto()
没有任何意义,因为你没有传递任何变量,所以你可能想要的是:
->join('partner_info', 'partner_info.rowid = partner_settings.partnerinfoid', array())
所以join()
的第一个参数是表名,第二个是条件,第三个是列。