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 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
)
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
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.
You haven't set the columns argument to an empty array, you're passing the array as the second argument to
quoteInto()
. You have:The
quoteInto()
serves no purpose since you aren't passing in any variables, so what you probably want is:so the first parameter to
join()
is the table name, the second is the condition, the third is the columns.