Zend DB连接选择所有列 [英] Zend DB join selects all columns

查看:82
本文介绍了Zend DB连接选择所有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Zend_Db_Select执行查询.这是我的代码:

I am attempting to perform a query using Zend_Db_Select. Here is my code:

 $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是一个包含以下值的数组:

$data1 is an array containing these values:

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查询如下:

The resulting MYSQL query looks like this:

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列子句:partner_info.*,partner_shipping.*我不想包含这些表中的所有列.我已将join()列参数设置为空array(),但这无济于事.

My biggest problem is with the SELECT columns clause which includes: partner_info.*, partner_shipping.* I don't want to include all columns from these tables. I have set the join() columns argument to empty array(), but it doesn't help.

有人找到这个问题的解决方案吗?我一直在徒劳地搜寻.

Has anyone found a solution to this problem? I have been searching futilely.

推荐答案

您尚未将columns参数设置为空数组,而是将数组作为第二个参数传递给quoteInto().你有:

You haven't set the columns argument to an empty array, you're passing the array as the second argument to quoteInto(). You have:

->join('partner_info', $db->quoteInto('partner_info.rowid = partner_settings.partnerinfoid', array()))

quoteInto()没有任何作用,因为您没有传递任何变量,所以您可能想要的是:

The quoteInto() serves no purpose since you aren't passing in any variables, so what you probably want is:

->join('partner_info', 'partner_info.rowid = partner_settings.partnerinfoid', array())

join()的第一个参数是表名,第二个是条件,第三个是列.

so the first parameter to join() is the table name, the second is the condition, the third is the columns.

这篇关于Zend DB连接选择所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆