public StatementPrefetch::execute($args = array(), $options = array())
Executes a prepared statement
Parameters
$args: An array of values with as many elements as there are bound parameters in the SQL statement being executed.
$options: An array of options for this query.
Return value
TRUE on success, or FALSE on failure.
Overrides StatementInterface::execute
File
- core/lib/Drupal/Core/Database/StatementPrefetch.php, line 139
Class
- StatementPrefetch
- An implementation of StatementInterface that prefetches all data.
Namespace
Drupal\Core\Database
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | public function execute( $args = array (), $options = array ()) { if (isset( $options [ 'fetch' ])) { if ( is_string ( $options [ 'fetch' ])) { // Default to an object. Note: db fields will be added to the object // before the constructor is run. If you need to assign fields after // the constructor is run. See https://www.drupal.org/node/315092. $this ->setFetchMode(\PDO::FETCH_CLASS, $options [ 'fetch' ]); } else { $this ->setFetchMode( $options [ 'fetch' ]); } } $logger = $this ->dbh->getLogger(); if (! empty ( $logger )) { $query_start = microtime(TRUE); } // Prepare the query. $statement = $this ->getStatement( $this ->queryString, $args ); if (! $statement ) { $this ->throwPDOException(); } $return = $statement ->execute( $args ); if (! $return ) { $this ->throwPDOException(); } if ( $options [ 'return' ] == Database::RETURN_AFFECTED) { $this ->rowCount = $statement ->rowCount(); } // Fetch all the data from the reply, in order to release any lock // as soon as possible. $this ->data = $statement ->fetchAll(\PDO::FETCH_ASSOC); // Destroy the statement as soon as possible. See the documentation of // \Drupal\Core\Database\Driver\sqlite\Statement for an explanation. unset( $statement ); $this ->resultRowCount = count ( $this ->data); if ( $this ->resultRowCount) { $this ->columnNames = array_keys ( $this ->data[0]); } else { $this ->columnNames = array (); } if (! empty ( $logger )) { $query_end = microtime(TRUE); $logger ->log( $this , $args , $query_end - $query_start ); } // Initialize the first row in $this->currentRow. $this ->next(); return $return ; } |
Please login to continue.