Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a sql query in zend framework 2?

I want to execute a query like the following query in zf2.

SHOW COLUMNS FROM Mytable LIKE 'Mycolumn'

What is the correct way of doing so?

By the way i am using AbstractTableGateway class.

like image 902
rahim asgari Avatar asked Dec 09 '22 19:12

rahim asgari


2 Answers

I do it like this:

  1. Create an adapter
  2. Pass it to the chosen class and run something like this:

    $sql = "SHOW COLUMNS FROM Mytable LIKE 'Mycolumn'"; 
    
    $statement = $this->adapter->query($sql); 
    return $statement->execute(); 
    
like image 127
michaelbn Avatar answered Dec 11 '22 07:12

michaelbn


I know reply on a very old thread, but maybe some one 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;
like image 25
Neelam Gahlyan Avatar answered Dec 11 '22 09:12

Neelam Gahlyan