PDOStatement() public method

Assigns the pdostatement object to this object.
public PDOStatement ( PDOStatement &$PDOStatement = false )
$PDOStatement PDOStatement The PDO Statement Object being assigned.
Ejemplo n.º 1
0
 /**
  * Executes a string of SQL. Returns a @@DataSet object. This is an override
  * method because of SQL Server's lack of a LIMIT clause.
  *
  * @param string $Sql A string of SQL to be executed.
  */
 public function Query($Sql)
 {
     if ($Sql == '') {
         trigger_error(ErrorMessage('Database was queried with an empty string.', $this->ClassName, 'Query'), E_USER_ERROR);
     }
     // Make sure that we don't need to wipe out the pdo statement (and related named parameters)
     if ($this->_PDOStatement !== FALSE && $Sql != $this->_PDOStatement->queryString) {
         // echo '<div>Existing: '.$this->_PDOStatement->queryString.'</div>';
         // echo '<div>New: '.$Sql.'</div>';
         $this->_ResetPDOStatement();
     }
     // Save the query for debugging
     $this->Queries[] = $Sql;
     // Start the Query Timer
     $TimeStart = list($sm, $ss) = explode(' ', microtime());
     // Run the Query
     if (count($this->_NamedParameters) > 0) {
         if ($this->_PDOStatement === FALSE) {
             $this->_PDOStatement = $this->Connection()->prepare($Sql);
         }
         $this->_PDOStatement->execute($this->_NamedParameters);
     } else {
         $this->_PDOStatement = $this->Connection()->query($Sql);
     }
     if ($this->_PDOStatement === FALSE) {
         $Error = $this->Connection()->errorInfo();
         trigger_error(ErrorMessage($Error[2], $this->ClassName, 'Query', $Sql), E_USER_ERROR);
     }
     // Aggregate the query times
     $TimeEnd = list($em, $es) = explode(' ', microtime());
     $this->_ExecutionTime += $em + $es - ($sm + $ss);
     $this->QueryTimes[] = $em + $es - ($sm + $ss);
     // Did this query modify data in any way?
     if (preg_match('/^\\s*"?(insert|update|delete|replace|create|drop|load data|copy|alter|grant|revoke|lock|unlock)\\s+/i', $Sql)) {
         return TRUE;
     }
     // Dispose of unneeded rows
     $i = 0;
     while ($i < $this->_Offset && $this->_PDOStatement->fetch()) {
         ++$i;
     }
     // Set the limit back to 0
     $this->_Offset = 0;
     // Create a DataSet to manage the resultset
     $ResultSet = new Gdn_DataSet();
     $ResultSet->Connection =& $this->_Connection;
     // Not using $this->Connection() because we know for a fact that the connection was created a few lines above.
     $ResultSet->PDOStatement($this->_PDOStatement);
     return $ResultSet;
 }