示例#1
0
文件: Query.php 项目: rrelmy/rorm
 /**
  * @return bool
  *
  * @todo probably we can unset query an params to free up memory
  */
 protected function execute()
 {
     $this->statement = $this->dbh->prepare($this->query);
     // set fetchMode to assoc, it is easier to copy data from an array than an object
     $this->statement->setFetchMode(PDO::FETCH_ASSOC);
     return $this->statement->execute($this->params);
 }
示例#2
0
 /**
  * ****************************************
  * *********** PRIVATE METHODS ************
  * ****************************************
  */
 private function Connect()
 {
     $this->Conn = parent::getConn();
     $this->Read = $this->Conn->prepare($this->Select);
     // Retornar resultados em arrays
     $this->Read->setFetchMode(PDO::FETCH_ASSOC);
 }
示例#3
0
文件: Statement.php 项目: shen2/mypdo
 protected function _fetchAll()
 {
     switch ($this->_fetchMode) {
         case self::FETCH_DATAOBJECT:
             self::$_stmt->setFetchMode(PDO::FETCH_ASSOC);
             $rowset = new \SplFixedArray(self::$_stmt->rowCount());
             $rowClass = $this->_fetchArgument;
             foreach (self::$_stmt as $index => $data) {
                 $rowset[$index] = new $rowClass($data, true, $this->_ctorArgs);
             }
             return $rowset;
         case self::FETCH_CLASSFUNC:
             self::$_stmt->setFetchMode(PDO::FETCH_ASSOC);
             $rowset = new \SplFixedArray(self::$_stmt->rowCount());
             $classFunc = $this->_fetchArgument;
             foreach (self::$_stmt as $index => $data) {
                 $rowClass = $classFunc($data);
                 $rowset[$index] = new $rowClass($data, true, $this->_ctorArgs);
             }
             return $rowset;
         default:
             if (isset($this->_ctorArgs)) {
                 return self::$_stmt->fetchAll($this->_fetchMode, $this->_fetchArgument, $this->_ctorArgs);
             }
             if (isset($this->_fetchArgument)) {
                 return self::$_stmt->fetchAll($this->_fetchMode, $this->_fetchArgument);
             }
             if (isset($this->_fetchMode)) {
                 return self::$_stmt->fetchAll($this->_fetchMode);
             }
     }
 }
示例#4
0
文件: Cursor.php 项目: boofw/phpole
 function rewind()
 {
     $this->PDOStatement = $this->pdo->prepare($this->sql . ' ' . $this->ordersql . ' ' . $this->limitsql);
     $this->PDOStatement->execute($this->params);
     $this->PDOStatement->setFetchMode(PDO::FETCH_ASSOC);
     $this->position = 0;
 }
示例#5
0
 /**
  * @param \PDOStatement $pdoStatement
  * @param string $classname optional
  */
 public function __construct($pdoStatement, $classname = '\\StdClass')
 {
     $this->pdoStatement = $pdoStatement;
     $this->count = $this->pdoStatement->rowCount();
     $this->classname = $classname;
     $this->pdoStatement->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $this->classname);
 }
示例#6
0
 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     try {
         if (substr($queryString, 0, 2) === '::') {
             $connection->getPdo()->{substr($queryString, 2)}();
         } elseif ($queryString !== NULL) {
             static $types = ['boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL];
             $this->pdoStatement = $connection->getPdo()->prepare($queryString);
             foreach ($params as $key => $value) {
                 $type = gettype($value);
                 $this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, isset($types[$type]) ? $types[$type] : PDO::PARAM_STR);
             }
             $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
             $this->pdoStatement->execute();
         }
     } catch (\PDOException $e) {
         $e = $this->supplementalDriver->convertException($e);
         $e->queryString = $queryString;
         throw $e;
     }
     $this->time = microtime(TRUE) - $time;
 }
示例#7
0
 /**
  * PRIVATE METODOS
  */
 private function Connect()
 {
     /** Pega a Conexão com a Class Pai Conn e atribui ao $this->Conn */
     $this->Conn = parent::getConn();
     /** Cria o Prepare Statement do Select */
     $this->Read = $this->Conn->prepare($this->Select);
     /** Seta o retorno dos dados no Formato fetch_assoc */
     $this->Read->setFetchMode(PDO::FETCH_ASSOC);
 }
示例#8
0
文件: Query.php 项目: thezawad/vakuum
 public function execute()
 {
     try {
         $this->stmt->execute();
         $this->stmt->setFetchMode(PDO::FETCH_ASSOC);
         ++self::$queryCount;
     } catch (PDOException $e) {
         echo $this->stmt->queryString;
         throw $e;
     }
 }
示例#9
0
 /**
  * Run a query against a database.  Get a result
  * @param string $query The SQL to run against the database
  * @param array $args An associative array of query parameters
  * @return bool|\PDOStatement False if query fails, results in this database's fetch_class if successful
  * @throws \Exception
  */
 public function query($query, $args = array())
 {
     if (!empty($this->pdo_statement)) {
         $this->pdo_statement->closeCursor();
     }
     if ($this->pdo_statement = $this->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true))) {
         $this->pdo_statement->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, $this->fetch_class, [$this]);
         if (!$this->pdo_statement->execute($args)) {
             throw new \Exception($this->pdo_statement->errorInfo());
         }
         return true;
     } else {
         throw new \Exception($this->errorInfo());
     }
 }
示例#10
0
 function __construct(SblamBase $base, PDOStatement $pdo)
 {
     $this->base = $base;
     $this->pdo = $pdo;
     $pdo->setFetchMode(PDO::FETCH_ASSOC);
     $this->next();
 }
示例#11
0
 /**
  * @param \PDOStatement $statement
  * @param int           $fetchMode
  *
  * @return \Kisma\Core\Tools\DataReader
  */
 public function setStatement($statement, $fetchMode = \PDO::FETCH_ASSOC)
 {
     if (null !== ($this->_statement = $statement)) {
         $this->_statement->setFetchMode($fetchMode);
     }
     return $this;
 }
示例#12
0
 /**
  *  Sets the fetch mode.
  *
  *  @param string $fetch_style   Controls how the rows will be returned.
  *  @param obj $obj              The object to be fetched into for use with FETCH_INTO.
  *  @access protected
  *  @return int
  */
 protected function _set_fetch_mode($fetch_style, $obj = null)
 {
     switch ($fetch_style) {
         case 'assoc':
             $this->_statement->setFetchMode(\PDO::FETCH_ASSOC);
             break;
         case 'both':
             $this->_statement->setFetchMode(\PDO::FETCH_BOTH);
             break;
         case 'into':
             $this->_statement->setFetchMode(\PDO::FETCH_INTO, $obj);
             break;
         case 'lazy':
             $this->_statement->setFetchMode(\PDO::FETCH_LAZY);
             break;
         case 'num':
             $this->_statement->setFetchMode(\PDO::FETCH_NUM);
             break;
         case 'obj':
             $this->_statement->setFetchMode(\PDO::FETCH_OBJ);
             break;
         default:
             $this->_statement->setFetchMode(\PDO::FETCH_ASSOC);
             break;
     }
 }
示例#13
0
 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     if (substr($queryString, 0, 2) === '::') {
         $connection->getPdo()->{substr($queryString, 2)}();
     } elseif ($queryString !== NULL) {
         $this->pdoStatement = $connection->getPdo()->prepare($queryString);
         $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
         $this->pdoStatement->execute($params);
     }
     $this->time = microtime(TRUE) - $time;
 }
示例#14
0
 /**
  * Changes the fetching mode affecting \Phalcon\Db\Result\Pdo::fetch()
  *
  *<code>
  *  //Return array with integer indexes
  *  $result->setFetchMode(Phalcon\Db::FETCH_NUM);
  *
  *  //Return associative array without integer indexes
  *  $result->setFetchMode(Phalcon\Db::FETCH_ASSOC);
  *
  *  //Return associative array together with integer indexes
  *  $result->setFetchMode(Phalcon\Db::FETCH_BOTH);
  *
  *  //Return an object
  *  $result->setFetchMode(Phalcon\Db::FETCH_OBJ);
  *</code>
  *
  * @param int $fetchMode
  * @throws Exception
  */
 public function setFetchMode($fetchMode)
 {
     if (is_int($fetchMode) === false) {
         throw new Exception('Invalid parameter type.');
     }
     switch ($fetchMode) {
         case 1:
             $fetchType = 2;
             break;
         case 2:
             $fetchType = 4;
             break;
         case 3:
             $fetchType = 3;
             break;
         case 4:
             $fetchType = 5;
             break;
         default:
             $fetchType = 0;
             break;
     }
     if ($fetchType !== 0) {
         $this->_pdoStatement->setFetchMode($fetchType);
         $this->_fetchMode = $fetchType;
     }
 }
示例#15
0
 /**
  * Получение объекта из запроса
  * @return Item
  */
 public function fetchObject(\PDOStatement $statement)
 {
     $statement->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $this->getItemClass(), array($this->getManager(), $this->getTable(), false));
     /** @var Item $obj */
     $obj = $statement->fetch();
     return $obj;
 }
示例#16
0
 /**
  * @param PDOStatement $stm
  * @param array $data
  * @return array
  */
 protected function get_row(PDOStatement $stm, array $data = array())
 {
     $data ? $stm->execute($data) : $stm->execute();
     $stm->setFetchMode(PDO::FETCH_ASSOC);
     $var = $stm->fetch();
     return $var;
 }
示例#17
0
 public function setFetchMode($fetchStyle, $params = NULL)
 {
     // This thin wrapper is necessary to shield against the weird signature
     // of PDOStatement::setFetchMode(): even if the second and third
     // parameters are optional, PHP will not let us remove it from this
     // declaration.
     return parent::setFetchMode($fetchStyle);
 }
示例#18
0
 /**
  * Execute a SQL statement.
  *
  * @param string $query the SQL statement
  * @param array $args values for the bound parameters
  * @return boolean true on success, false on failure
  */
 public function query($query, $args = array())
 {
     if ($this->pdo_statement != null) {
         $this->pdo_statement->closeCursor();
     }
     // Allow plugins to modify the query
     $query = Plugins::filter('query', $query, $args);
     // Translate the query for the database engine
     $query = $this->sql_t($query, $args);
     // Replace braced table names in the query with their prefixed counterparts
     $query = self::filter_tables($query);
     // Allow plugins to modify the query after it has been processed
     $query = Plugins::filter('query_postprocess', $query, $args);
     if ($this->pdo_statement = $this->pdo->prepare($query)) {
         if ($this->fetch_mode == \PDO::FETCH_CLASS) {
             /* Try to get the result class autoloaded. */
             if (!class_exists($this->fetch_class_name, true)) {
                 $class_name = $this->fetch_class_name;
                 // @todo This is a GIANT namespace kludge, replacing Model class names with no namespace that don't exist with a default prefixed class
                 if (strpos($class_name, '\\') == false) {
                     $class_name = '\\Habari\\' . $class_name;
                     $this->fetch_class_name = $class_name;
                     if (!class_exists($this->fetch_class_name, true)) {
                         throw new \Exception('The model class that was specified for data retreival could not be loaded.');
                     }
                 }
             }
             /* Ensure that the class is actually available now, otherwise segfault happens (if we haven't died earlier anyway). */
             if (class_exists($this->fetch_class_name)) {
                 $this->pdo_statement->setFetchMode(\PDO::FETCH_CLASS, $this->fetch_class_name, array());
             } else {
                 /* Die gracefully before the segfault occurs */
                 echo '<br><br>' . _t('Attempt to fetch in class mode with a non-included class') . '<br><br>';
                 return false;
             }
         } else {
             $this->pdo_statement->setFetchMode($this->fetch_mode);
         }
         /* If we are profiling, then time the query */
         if ($this->keep_profile) {
             $profile = new QueryProfile($query);
             $profile->params = $args;
             $profile->start();
         }
         if (!$this->pdo_statement->execute($args)) {
             $this->add_error(array('query' => $query, 'error' => $this->pdo_statement->errorInfo()));
             return false;
         }
         if ($this->keep_profile) {
             $profile->stop();
             $this->profiles[] = $profile;
         }
         return true;
     } else {
         $this->add_error(array('query' => $query, 'error' => $this->pdo->errorInfo()));
         return false;
     }
 }
示例#19
0
 /**
  * Set the default fetch mode for this statement.
  *
  * @param int   $mode The fetch mode.
  * @return bool
  * @throws Zend_Db_Statement_Exception
  */
 public function setFetchMode($mode)
 {
     $this->_fetchMode = $mode;
     try {
         return $this->_stmt->setFetchMode($mode);
     } catch (PDOException $e) {
         require_once 'Zend/Db/Statement/Exception.php';
         throw new Zend_Db_Statement_Exception($e->getMessage());
     }
 }
示例#20
0
 public function __construct(\PDOStatement $stmt, ActiveRecord $model)
 {
     $this->stmt = $stmt;
     $this->model = $model;
     $stmt->setFetchMode(\PDO::FETCH_CLASS, $model->className(), array(false));
     //		$this->id=self::$idCount++;
     //
     //		ZLog::Write(LOGLEVEL_DEBUG, $stmt->queryString);
     //		self::$aliveStmts[$this->id]=$stmt->queryString;
 }
示例#21
0
 /**
  * @return \PDOStatement
  */
 protected function getTableExistsStmt()
 {
     if (!$this->tblExistsStmt) {
         $this->tblExistsStmt = $this->conn->prepare('SELECT COUNT(TABLE_NAME) as occ
               FROM information_schema.TABLES
               WHERE TABLE_NAME = :name AND TABLE_SCHEMA = :schema');
         $this->tblExistsStmt->setFetchMode(\PDO::FETCH_ASSOC);
     }
     return $this->tblExistsStmt;
 }
示例#22
0
文件: DB.php 项目: sysulsj/phpwebsite
 /**
  * Returns a passed $object parameter with values set from the current query.
  *
  * @param object $object
  * @return object
  */
 public function fetchInto($object)
 {
     $this->checkStatement();
     $this->pdo_statement->setFetchMode(\PDO::FETCH_INTO, $object);
     $result = $this->pdo_statement->fetch();
     if (empty($result)) {
         $this->clearStatement();
     }
     return $result;
 }
 public function setFetchMode($mode, $arg1 = null, $arg2 = null)
 {
     $this->_fetchMode = $mode;
     if ($arg1 === null) {
         return parent::setFetchMode($mode);
     } else {
         if ($arg2 === null) {
             return parent::setFetchMode($mode, $arg1);
         }
     }
     return parent::setFetchMode($mode, $arg1, $arg2);
 }
示例#24
0
文件: DB.php 项目: jlsa/justitia
 static function fetch_all($class, PDOStatement $query)
 {
     // fetch submissions
     $result = array();
     $query->setFetchMode(PDO::FETCH_ASSOC);
     foreach ($query as $data) {
         $result[] = new $class($data);
     }
     DB::check_errors($query);
     $query->closeCursor();
     return $result;
 }
示例#25
0
 public function setFetchMode($mode, $params = NULL)
 {
     if ($this->_statement instanceof \PDOStatement) {
         switch ($mode) {
             case PDO::FETCH_ASSOC:
             case PDO::FETCH_BOTH:
                 $this->_statement->setFetchMode($mode);
                 break;
             default:
                 throw new UnsupportedFetchMode("FetchMode {$mode} is not supported by PgBabylon");
         }
     }
 }
示例#26
0
 /**
  * 执行sql语句
  * @throws \PDOException
  * @param string $sql sql语句
  * @param array $params 预绑定参数数组
  * @return $this
  */
 public function query($sql, array $params = array())
 {
     try {
         $this->stmt = $this->pdo->prepare($sql);
         $this->bindValue($params);
         $this->stmt->execute();
         $this->stmt->setFetchMode(\PDO::FETCH_ASSOC);
     } catch (\PDOException $e) {
         $this->getDebug() and $this->echoDebug($sql, $params, $e);
         throw $e;
     }
     return $this;
 }
示例#27
0
 public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
 {
     // This thin wrapper is necessary to shield against the weird signature
     // of PDOStatement::setFetchMode(): even if the second and third
     // parameters are optional, PHP will not let us remove it from this
     // declaration.
     if ($arg2 === null && $arg3 === null) {
         return parent::setFetchMode($fetchMode);
     }
     if ($arg3 === null) {
         return parent::setFetchMode($fetchMode, $arg2);
     }
     return parent::setFetchMode($fetchMode, $arg2, $arg3);
 }
示例#28
0
 /**
  * Sets the fetch mode.
  *
  * @param string $fetch_style
  *            Controls how the rows will be returned.
  * @param obj $obj
  *            The object to be fetched into for use with
  *            FETCH_INTO.
  * @return integer
  */
 protected function setFetchMode($fetch_style, $obj = null)
 {
     switch ($fetch_style) {
         case 'assoc':
             $this->statement->setFetchMode(PDO::FETCH_ASSOC);
             break;
         case 'into':
             $this->statement->setFetchMode(PDO::FETCH_INTO, $obj);
             break;
         default:
             $this->statement->setFetchMode(PDO::FETCH_ASSOC);
             break;
     }
 }
示例#29
0
 /**
  * Set the fetch mode.
  * @param int $mode  the mode, a PDO::FETCH_* constant
  * @param mixed $arg1 a parameter for the given mode
  * @param mixed $arg2 a parameter for the given mode
  */
 public function setFetchMode($mode, $arg1 = null, $arg2 = null)
 {
     $this->_fetchMode = $mode;
     // depending the mode, original setFetchMode throw an error if wrong arguments
     // are given, even if there are null
     if ($arg1 === null) {
         return parent::setFetchMode($mode);
     } else {
         if ($arg2 === null) {
             return parent::setFetchMode($mode, $arg1);
         }
     }
     return parent::setFetchMode($mode, $arg1, $arg2);
 }
示例#30
0
 /**
  * @see Loadable::load
  * @param \PDOStatement $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return Document|Result|NULL
  */
 public function load($source, $contentType, $options = [])
 {
     if ($source instanceof \PDOStatement) {
         $document = new Document('1.0', 'UTF-8');
         $document->registerNamespace('json', self::XMLNS);
         $root = $document->appendElement('json:json');
         $source->setFetchMode(\PDO::FETCH_OBJ);
         foreach ($source as $row) {
             $child = $root->appendElement('_');
             $this->transferTo($child, $row, 1);
         }
         return new Result($document, 'text/xml');
     }
     return NULL;
 }