当前位置: 首页>>代码示例>>PHP>>正文


PHP PDOStatement类代码示例

本文整理汇总了PHP中PDOStatement的典型用法代码示例。如果您正苦于以下问题:PHP PDOStatement类的具体用法?PHP PDOStatement怎么用?PHP PDOStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PDOStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: convertToNativeTypes

 /**
  * Converts columns from strings to types according to 
  * PDOStatement::columnMeta
  * http://stackoverflow.com/a/9952703/3006989
  * 
  * @param PDOStatement $st
  * @param array $assoc returned by PDOStatement::fetch with PDO::FETCH_ASSOC
  * @return copy of $assoc with matching type fields
  */
 public static function convertToNativeTypes(PDOStatement $statement, $rows)
 {
     for ($i = 0; $columnMeta = $statement->getColumnMeta($i); $i++) {
         $type = $columnMeta['native_type'];
         switch ($type) {
             case 'DECIMAL':
             case 'TINY':
             case 'SHORT':
             case 'LONG':
             case 'LONGLONG':
             case 'INT24':
                 if (isset($rows[$columnMeta['name']])) {
                     $rows[$columnMeta['name']] = $rows[$columnMeta['name']] + 0;
                 } else {
                     if (is_array($rows) || $rows instanceof Traversable) {
                         foreach ($rows as &$row) {
                             if (isset($row[$columnMeta['name']])) {
                                 $row[$columnMeta['name']] = $row[$columnMeta['name']] + 0;
                             }
                         }
                     }
                 }
                 break;
             case 'DATETIME':
             case 'DATE':
             case 'TIMESTAMP':
                 // convert to date type?
                 break;
                 // default: keep as string
         }
     }
     return $rows;
 }
开发者ID:fpdo,项目名称:fluentpdo,代码行数:42,代码来源:FluentUtils.php

示例2: __construct

 function __construct(SblamBase $base, PDOStatement $pdo)
 {
     $this->base = $base;
     $this->pdo = $pdo;
     $pdo->setFetchMode(PDO::FETCH_ASSOC);
     $this->next();
 }
开发者ID:bitemyapp,项目名称:Sblam,代码行数:7,代码来源:sblambase.php

示例3: execute

 /**
  * @see \PDOStatement::execute
  */
 public function execute(array $input_parameters = array())
 {
     $start = microtime(true);
     $result = $this->statement->execute($input_parameters);
     $this->pdo->addLog(array('query' => $this->statement->queryString, 'time' => microtime(true) - $start, 'values' => array_merge($this->binds, $input_parameters)));
     return $result;
 }
开发者ID:so222es,项目名称:gesall,代码行数:10,代码来源:PdoStatement.php

示例4: bindValues

 private function bindValues(\PDOStatement $stmt, array $values)
 {
     foreach ($values as $key => $value) {
         $stmt->bindValue($key, $value, self::types[$key]);
     }
     return $stmt;
 }
开发者ID:zhaoyiyi,项目名称:php-project,代码行数:7,代码来源:Page.php

示例5: execute

 public static function execute(\PDOStatement $stmt)
 {
     if ($stmt->execute()) {
         return true;
     }
     return false;
 }
开发者ID:mejt,项目名称:Krauza,代码行数:7,代码来源:ModifyData.php

示例6: bind

 /**
  * @override
  */
 public function bind(PDOStatement $stmt, $value)
 {
     $param = $value[0];
     $param->__init__();
     $logger = HermitLoggerManager::getLogger();
     if ($logger->isDebugEnabled()) {
         $buf = '';
         foreach ($this->bindKeys as $key) {
             $v = null;
             if ($param instanceof HermitParam) {
                 $v = $param->get($key);
             } else {
                 $method = $this->reflector->getMethod('get' . ucfirst($key));
                 $v = $method->invoke($param);
             }
             $buf .= $key . ' => ' . $v;
             $buf .= ', ';
         }
         $logger->debug('{%s} statement binds parameter {:key => param} = %s', __CLASS__, $buf);
     }
     foreach ($this->bindKeys as $index => $key) {
         if ($this->info->typeofIn($key)) {
             $stmt->bindValue(':' . $key, $param->get($key));
         }
     }
 }
开发者ID:nowelium,项目名称:Hermit,代码行数:29,代码来源:HermitMySqlProcedureParameter.php

示例7: preforward

 /**
  *  CSVを出力する
  *  @access public
  *  @param CSVWriter $writer CSV書き込みクラス
  *  @param PDOStatement|array $sth 出力する値
  *  @param string $filename 出力するCSV名
  *  @see Admin_ViewClass::preforward
  */
 function preforward($writer, $sth, $filename)
 {
     //CSV出力
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Content-Type: text/csv;charset=SJIS-win');
     $writer->charset = 'SJIS-win';
     // 取得結果が0件の場合のヘッダ出力用
     //         $result = $sth->fetchAll();
     //         if(count($result)==0){
     //             $result=(array(0));
     //         }
     //     	foreach ($result as $r) {
     //     	    $writer->write($r);
     //     	}
     $row = array();
     $count = 0;
     while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
         $count++;
         $writer->write($row);
     }
     if (0 == $count) {
         $writer->write($row);
     }
     exit;
 }
开发者ID:weiweiabc109,项目名称:test_project1,代码行数:33,代码来源:Csv.php

示例8: bind

 public function bind(PDOStatement $stmt, $value)
 {
     $param = $value[0];
     $param->__init__();
     $propertyNames = $param->getPropertyNames();
     foreach ($this->bindKeys as $index => $key) {
         $bindKey = ':' . $key;
         if ($this->info->typeofIn($key)) {
             if (!in_array($key, $propertyNames)) {
                 throw new InvalidArgumentException('param ' . $param . ' has not propery: ' . $key . ' instatement: ' . $stmt->queryString);
             }
             $stmt->bindParam($bindKey, $param->get($key));
             continue;
         }
         $paramValue = null;
         if ($param->issetValue($key)) {
             $paramValue = $param->get($key);
         }
         if (null === $paramValue) {
             $stmt->bindParam($bindKey, $paramValue, PDO::PARAM_NULL | PDO::PARAM_INPUT_OUTPUT);
             continue;
         }
         $gettype = gettype($paramValue);
         $paramType = -1;
         if (isset(self::$pdoTypes[$gettype])) {
             $paramType = self::$pdoTypes[$gettype] | PDO::PARAM_INPUT_OUTPUT;
         } else {
             $paramType = PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT;
         }
         $stmt->bindParam($bindKey, $paramValue, $paramType);
     }
 }
开发者ID:nowelium,项目名称:Hermit,代码行数:32,代码来源:HermitProcedureParameter.php

示例9: rewind

 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;
 }
开发者ID:boofw,项目名称:phpole,代码行数:7,代码来源:Cursor.php

示例10: get_row

 /**
  * @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;
 }
开发者ID:novichkovv,项目名称:newddetox,代码行数:12,代码来源:model.php

示例11: bindParameters

 /**
  * Binds the resolved parameters to the supplied PDO statement.
  *
  * @param \PDOStatement              $statement
  * @param IResolvedParameterRegistry $resolvedParameters
  *
  * @return void
  */
 public function bindParameters(\PDOStatement $statement, IResolvedParameterRegistry $resolvedParameters)
 {
     $resolvedExpressions = $this->parameters->resolve($resolvedParameters);
     foreach ($resolvedExpressions->getParameters() as $parameter) {
         $statement->bindValue($parameter->getData(), $resolvedExpressions->getValue($parameter));
     }
 }
开发者ID:timetoogo,项目名称:pinq.demo.sql,代码行数:15,代码来源:Query.php

示例12: bindValueAndExecuteInsertOrUpdate

 private function bindValueAndExecuteInsertOrUpdate(PDOStatement $stm, Contact $contact)
 {
     $stm->bindValue(':name', $contact->getName(), PDO::PARAM_STR);
     $stm->bindValue(':photo', $contact->getPhoto(), PDO::PARAM_STR);
     $stm->bindValue(':email', $contact->getEmail(), PDO::PARAM_STR);
     return $stm->execute();
 }
开发者ID:lga37,项目名称:contacts,代码行数:7,代码来源:ContactSQLStorage.php

示例13: executeFetchAllStatement

 public static function executeFetchAllStatement(\PDOStatement $stmt)
 {
     if (!$stmt->execute()) {
         return [];
     }
     return $stmt->fetchAll(\PDO::FETCH_ASSOC);
 }
开发者ID:mejt,项目名称:Krauza,代码行数:7,代码来源:FetchData.php

示例14: dispose

 public function dispose()
 {
     if (!$this->is_disposed) {
         $this->statement->closeCursor();
         $this->is_disposed = true;
     }
 }
开发者ID:AroundPBT,项目名称:PHPBoost,代码行数:7,代码来源:PDOInjectQueryResult.class.php

示例15: next

 /**
  * @inheritDoc
  */
 public function next()
 {
     $this->cursorOffset++;
     // Fetching one row, located at the given offset in the result set
     // (This is what PDO::FETCH_ORI_ABS is for).
     $this->currentRow = $this->statement->fetch(\PDO::FETCH_ASSOC, \PDO::FETCH_ORI_ABS, $this->cursorOffset);
 }
开发者ID:adrilo,项目名称:spout-pdo-example,代码行数:10,代码来源:SingleFetchIterator.php


注:本文中的PDOStatement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。