3

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...

2 Answers 2

2

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());
Sign up to request clarification or add additional context in comments.

Comments

0
    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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.