Cake\Database\Connection::execute PHP Method

execute() public method

Executes a query using $params for interpolating values and $types as a hint for each those params.
public execute ( string $query, array $params = [], array $types = [] ) : Cake\Database\StatementInterface
$query string SQL to be executed and interpolated with $params
$params array list or associative array of params to be interpolated in $query as values
$types array list or associative array of types to be used for casting values in query
return Cake\Database\StatementInterface executed statement
    public function execute($query, array $params = [], array $types = [])
    {
        if (!empty($params)) {
            $statement = $this->prepare($query);
            $statement->bind($params, $types);
            $statement->execute();
        } else {
            $statement = $this->query($query);
        }
        return $statement;
    }

Usage Example

 /**
  * Executes list of quries in one transaction.
  *
  * @param \Cake\Database\Connection $db Connection to run the SQL queries on.
  * @param  array $queries List of SQL statements.
  * @return void
  */
 protected function _execute($db, $queries = null)
 {
     $logQueries = $db->logQueries();
     if ($logQueries) {
         $db->logQueries(false);
     }
     $db->transactional(function ($db) use($queries) {
         $db->disableForeignKeys();
         foreach ($queries as $query) {
             $this->_io->out('.', 0);
             $db->execute($query)->closeCursor();
         }
         $db->enableForeignKeys();
     });
     if ($logQueries) {
         $db->logQueries(true);
     }
 }
All Usage Examples Of Cake\Database\Connection::execute