php 如何在 Zend 框架 2 中执行 sql 查询?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13619064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:47:27  来源:igfitidea点击:

How to execute a sql query in zend framework 2?

phpsqlzend-framework2

提问by rahim asgari

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

我想在 zf2 中执行类似于以下查询的查询。

SHOW COLUMNS FROM Mytable LIKE 'Mycolumn'

SHOW COLUMNS FROM Mytable LIKE 'Mycolumn'

What is the correct way of doing so?

这样做的正确方法是什么?

By the way i am using AbstractTableGatewayclass.

顺便说一下,我正在使用AbstractTableGateway类。

回答by michaelbn

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(); 
    
  1. 创建适配器
  2. 将它传递给所选的类并运行如下所示:

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

回答by Neelam Gahlyan

I know reply on a very old thread, but maybe some one looking for SELECT with LIKE

我知道在一个很旧的线程上回复,但也许有人在寻找带有 LIKE 的 SELECT

 $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;

回答by Balu Mahesh

This is Some thing found From Google,Hope This helps u...

这是从谷歌找到的一些东西,希望这可以帮助你...

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 Info Visit : click

更多信息请访问:点击