How can I use a stored procedure in a MySql database with Zend Framework?

前端 未结 4 1272
無奈伤痛
無奈伤痛 2020-12-02 12:44

I\'m recently have learned to use Zend Framework. I did a simple CRUD application. But now I want to use a existing database for a more complex application and I want to kno

4条回答
  •  無奈伤痛
    2020-12-02 13:10

    If someone is looking for ZendFramework 2 \ Zend Expressive using Zend\Db :

    There is another way to do this using createStatement() method.

    // prepare create statement from adapter
    $stmt = $this->getAdapter()->createStatement();
    
    $stmt->prepare('CALL myproc("myVal")');
    // execute sql query
    $records = $stmt->execute();
    // manipulate results
    if ($records instanceof ResultInterface && $records->isQueryResult()) {
        $resultSet = new ResultSet;
        $resultSet->initialize($records);
        // return records if found
        if (count($resultSet)) {
           // return array of result set
           return $resultSet->toArray();
        }
       // if no records found
       return array()
    
    }
    

提交回复
热议问题