简体   繁体   中英

How to SELECT on tables in zf2 using sql

How would you make this query on zf2 with Zend\\Db\\Sql\\Select?

 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  album.title LIKE '%Value_Title%'
        AND album.artist LIKE '%Value_Artist%'

I've tried different methods without success.

It must be something like this:

use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;
$where = new Where();
$where->like('album.title', '%' . $value_title . '%')
  ->like('album.artist', '%' . $Value_artist . '%');
$select = new Select();
$select->from('album')
   ->columns('id', 'title')
   ->join('pais', 'pais.id_album = album.id', [
       'nombre_pais'
   ])
   ->join('biografia', 'biografia.id_album = album.id', [
       'genero', 
       'ocupacion', 
       'sitio_web'
   ])
   ->where($where);

In the join method, field names should not be prefixed with the table name. This is the method that does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM