Reputation: 14834
so I have this code:
$db = new Zend_Db_Adapter_Pdo_Mysql($params);
$sql = $db->select()->from(array("r" => "recc"), array("r_id" => "refID"))->joinLeft(array("c" => "comment"), "r.refID = c.refID");
$results = $db->fetchAll($sql);
print_r($results);
which is supposed to translate to this query:
SELECT refID AS r_id FROM recc r LEFT JOIN comment c ON r.refID = c.refID
which is supposed to only return a single column r_id and it indeed returned that single column when executed with mysql query browser
but then when you execute it with db select and print_r the results, in addition to r_id it also returned a whole bunch of fields in table comment which are populated with empty data...
did I do something wrong? how do I get the thing to only return the single column as planned...
Upvotes: 3
Views: 527
Reputation: 7954
Try
print_r($results->toArray()); //Pure array format of result
array('') // If you dont want columns from a joining table you pass as the last parameter to the join
array('*') //IF you want all the fields
Upvotes: 0
Reputation: 9836
I think it's the joinLeft(). You may need to pass an empty array() as a third parameter.
$sql = $db->select()
->from(array("r" => "recc"), array("r_id" => "refID"))
->joinLeft(array("c" => "comment"), "r.refID = c.refID", array());
Upvotes: 2