0

how can get an sql query for this code in zf2 is only that don't return my all records that i need only some ones columns don.t get (nombre_pais, genero, ocupacion,sitio_web )

i'm trying this code in mysql console (query) it returns ok

 SELECT album.id, album.artist, album.title, pais.nombre_pais, biografia.genero, biografia.ocupacion, biografia.sitio_web
                 FROM album
                    INNER JOIN pais ON  pais.id_album = album.id
                    INNER JOIN biografia ON biografia.id_album = album.id
        WHERE   1 = 1
AND album.artist like '%value_artist%'
AND album.artist LIKE '%value_title%'

and this is my code in zf2 : it doesn't return ok. It returns only id, title, artist, and doesn't other columns from my other tables.

$where = new Where();
    if (isset($artist) and isset($title))
    {
    $where->like('album.title', '%' . $title . '%')
    ->like('album.artist', '%' . $artist . '%');
    }
    if (isset($artist))
    {
        $where->like('album.artist', '%' . $artist . '%');
    }
    if (isset($title))
    {
        $where->like('album.title', '%' . $title . '%');
    }
    $select = new Select();
    $select->from('album')
    ->columns(array ('id', 'artist','title'))
    ->join('pais', 'pais.id_album = album.id',array('nombre_pais'))
    ->join('biografia', 'biografia.id_album = album.id', array('genero', 'ocupacion', 'sitio_web'))
    ->where($where);

please some one help me to get my correct result

miken32
  • 42,008
  • 16
  • 111
  • 154
BlackHack123
  • 349
  • 1
  • 10

1 Answers1

1

To find out what the generated SQL will look like, you can use the $select's getSqlString() method:

$select->getSqlString();

For example:

 echo $select->getSqlString(); die();

http://framework.zend.com/manual/current/en/modules/zend.db.sql.html

calraiden
  • 1,686
  • 1
  • 27
  • 37