當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。