How to execute sql query in zend framework 2?

I want to execute a query, for example, the following query in zf2.

SHOW COLUMNS FROM Mytable LIKE 'Mycolumn'

What is the correct way?

By the way, I'm using the AbstractTableGateway class.

+4
source share
3 answers

I do it like this:

  • Create adapter
  • Pass it to the selected class and run something like this:

     $sql = "SHOW COLUMNS FROM Mytable LIKE 'Mycolumn'"; $statement = $this->adapter->query($sql); return $statement->execute(); 
+11
source

I know the answer to a very old thread, but maybe someone is looking for SELECT with LIKE

  $this->table = $data['table']; $select = new Select(); $spec = function (Where $where) { $where->like('company', '%1%'); }; $select->from($this->table); $select->where($spec); $resultSet = $this->selectWith($select); $resultSet->buffer(); return $resultSet; 
+2
source

This is something found on Google, Hope this helps you ...

 use Zend\Db\Sql\Sql; $sql = new Sql($adapter); $select = $sql->select(); // @return Zend\Db\Sql\Select $insert = $sql->insert(); // @return Zend\Db\Sql\Insert $update = $sql->update(); // @return Zend\Db\Sql\Update $delete = $sql->delete(); // @return Zend\Db\Sql\Delete 

For more information visit: click

0
source

All Articles