Search code examples
phpzend-frameworkzend-db

When I echo a Zend_Db query it contains 'ON Array', why?


Sql Query:

SELECT test.* FROM test JOIN test_shares
WHERE test.test_id = test_shares.test_id 
AND test_shares.email_address = '$email' 
AND test.url is NOT NULL ORDER BY title ASC;

Rewritten as Zend_Db_Select statement.

$select = $db->select ()
    ->from ( 'test', 'test.*' )
    ->join ( 'test_shares', array () )
    ->where ( 'test.test_id = test_shares.test_id')
    ->where ( 'test_shares.email_address = ?',  '$email')
    ->where ( 'test.url is NOT NULL')
    ->order ( 'title' );
echo $select;

Output:

SELECT test.* FROM test JOIN test_shares ON Array 
WHERE test.test_id = test_shares.test_id 
AND test_shares.email_address = '$email' 
AND test.url is NOT NULL ORDER BY title ASC

Please suggest why this 'ON Array' is showing.


Solution

  • Try this:

    $select = $db   ->select ()
        ->from ( 'movie', 'movie.*' )
        ->join(array('movie_shares'),  'movie.movie_id = movie_shares.movie_id');    
        ->where ( 'movie_shares.email_address = ?',  '$email')
        ->where ( 'movie.url is NOT NULL')
        ->order ( 'title' );
    echo $select;
    

    You're supplying an array where a string is expected for the ON clause, so PHP literally prints array() instead of the string.