當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PDOStatement::getColumnMeta方法代碼示例

本文整理匯總了PHP中PDOStatement::getColumnMeta方法的典型用法代碼示例。如果您正苦於以下問題:PHP PDOStatement::getColumnMeta方法的具體用法?PHP PDOStatement::getColumnMeta怎麽用?PHP PDOStatement::getColumnMeta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PDOStatement的用法示例。


在下文中一共展示了PDOStatement::getColumnMeta方法的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: fetchAll

 function fetchAll(PDOStatement $statement)
 {
     try {
         $columnCount = $statement->columnCount();
         $manualFetch = false;
         $booleanColumns = array();
         for ($i = 0; $i < $columnCount; $i++) {
             $meta = $statement->getColumnMeta($i);
             if ($meta['sqlite:decl_type'] == 'BOOLEAN') {
                 $manualFetch = true;
                 $booleanColumns[] = $meta['name'];
             }
         }
     } catch (PDOException $e) {
         return $statement->fetchAll();
     }
     if (!$manualFetch) {
         return $statement->fetchAll();
     } else {
         $results = array();
         while ($result = $statement->fetch()) {
             foreach ($booleanColumns as $column) {
                 $result->{$column} = $result->{$column} == 1;
             }
             $results[] = $result;
         }
         return $results;
     }
 }
開發者ID:nmcteam,項目名稱:recess,代碼行數:29,代碼來源:SqliteDataSourceProvider.class.php

示例3: getColumnMeta

 /**
  * Returns metadata for a column in a result set.
  *
  * @param int $column
  * @return mixed
  * @throws Zend_Db_Statement_Exception
  */
 public function getColumnMeta($column)
 {
     try {
         return $this->_stmt->getColumnMeta($column);
     } catch (PDOException $e) {
         require_once 'Zend/Db/Statement/Exception.php';
         throw new Zend_Db_Statement_Exception($e->getMessage());
     }
 }
開發者ID:jorgenils,項目名稱:zend-framework,代碼行數:16,代碼來源:Pdo.php

示例4: dump

 public function dump()
 {
     $metas = array();
     for ($col = 0, $nCols = $this->columnCount(); $col < $nCols; $col++) {
         $pdo_metas = parent::getColumnMeta($col);
         $metas[] = array('name' => $pdo_metas['name'], 'max_length' => $pdo_metas['len'], 'type' => $pdo_metas['native_type']);
     }
     return array('RESULTSET' => $this->fetchAll(Driver::FETCH_NUM), 'COLUMN_META' => $metas, 'CREATED' => $this->timeCreated);
 }
開發者ID:dario1985,項目名稱:adodb,代碼行數:9,代碼來源:Statement.php

示例5: getFields

 /**
  * @param \PDOStatement $stmt
  * @return array
  */
 private function getFields(\PDOStatement $stmt)
 {
     $fields = [];
     $columnCount = $stmt->columnCount();
     for ($i = 0; $i < $columnCount; $i++) {
         $fields[$i] = $stmt->getColumnMeta($i);
     }
     return $fields;
 }
開發者ID:atijust,項目名稱:mappa,代碼行數:13,代碼來源:Hydrator.php

示例6: bindColumns

 protected function bindColumns()
 {
     if (!$this->columnsBound) {
         $this->columnsBound = true;
         $this->actRow = array();
         $this->actRowIndex = array();
         $count = $this->pdoStmt->columnCount();
         for ($i = 0; $i < $count; $i++) {
             $meta = $this->pdoStmt->getColumnMeta($i);
             if (array_key_exists('native_type', $meta) && $meta['native_type'] == 'BLOB') {
                 $this->pdoStmt->bindColumn($i + 1, $this->actRow[$meta['name']], \PDO::PARAM_LOB);
             } else {
                 $this->pdoStmt->bindColumn($i + 1, $this->actRow[$meta['name']]);
             }
             $this->actRowIndex[$i] =& $this->actRow[$meta['name']];
         }
     }
 }
開發者ID:robo47,項目名稱:BlazeFramework,代碼行數:18,代碼來源:AbstractResultSet.php

示例7: load_col_info

 /**
  * Load the column metadata from the last query.
  * @return array
  */
 public function load_col_info()
 {
     if ($this->col_info) {
         return $this->col_info;
     }
     $num_fields = $this->result->columnCount();
     for ($i = 0; $i < $num_fields; $i++) {
         $this->col_info[$i] = (object) $this->result->getColumnMeta($i);
     }
     return $this->col_info;
 }
開發者ID:mpeshev,項目名稱:wp-db-driver,代碼行數:15,代碼來源:pdo_mysql.php

示例8: fetchMeta

 private function fetchMeta()
 {
     if ($this->fieldnames === null) {
         $this->rawFieldnames = [];
         $this->fieldnames = [];
         $this->tablenames = [];
         for ($i = 0; $i < $this->getFields(); ++$i) {
             $metadata = $this->stmt->getColumnMeta($i);
             // strip table-name from column
             $this->fieldnames[] = substr($metadata['name'], strlen($metadata['table'] . '.'));
             $this->rawFieldnames[] = $metadata['name'];
             if (!in_array($metadata['table'], $this->tablenames)) {
                 $this->tablenames[] = $metadata['table'];
             }
         }
     }
 }
開發者ID:redaxo,項目名稱:redaxo,代碼行數:17,代碼來源:sql.php

示例9: _getColumnDataType

 /**
  * Translate native pgtype (json for example) to PgBabylon\PDO::PARAM_*
  *
  * @param $columnIndex
  * @return int|null
  */
 protected function _getColumnDataType($columnIndex)
 {
     $meta = $this->_statement->getColumnMeta($columnIndex);
     switch ($meta['native_type']) {
         case 'json':
             return PDO::PARAM_JSON;
         case 'timestamp':
             return PDO::PARAM_DATETIME;
         case 'date':
             return PDO::PARAM_DATE;
         case '_text':
             return PDO::PARAM_ARRAY;
         case '_int4':
             return PDO::PARAM_ARRAY;
     }
     return null;
 }
開發者ID:rtshome,項目名稱:pgbabylon,代碼行數:23,代碼來源:PDOStatement.php

示例10: importFromPDO

 /**
  * Import table headers and data from \PDOStatement
  *
  * @param \PDOStatement $stmt
  */
 public function importFromPDO(\PDOStatement $stmt)
 {
     $this->_header = array();
     $i = 0;
     while (($column = $stmt->getColumnMeta($i++)) !== false) {
         $this->_header[] = $column['name'];
     }
     $this->_data = array();
     while (($row = $stmt->fetch(\PDO::FETCH_NUM)) !== false) {
         $this->_data[] = $row;
     }
     // if options is empty we want to regenerate defaults
     if (count($this->_options) < 1) {
         $this->setOptions();
     }
     $this->_executeFormats();
 }
開發者ID:kehet,項目名稱:php-cli-utils,代碼行數:22,代碼來源:Table.php

示例11: resultSet

 /**
  * Builds a map of the columns contained in a result
  *
  * @param PDOStatement $results
  * @return void
  */
 public function resultSet($results)
 {
     $this->map = array();
     $numFields = $results->columnCount();
     $index = 0;
     while ($numFields-- > 0) {
         $column = $results->getColumnMeta($index);
         if (empty($column['native_type'])) {
             $type = $column['len'] == 1 ? 'boolean' : 'string';
         } else {
             $type = $column['native_type'];
         }
         if (strpos($column['name'], '__')) {
             list($column['table'], $column['name']) = explode('__', $column['name']);
         }
         if (!empty($column['table']) && strpos($column['name'], $this->virtualFieldSeparator) === false) {
             $this->map[$index++] = array($column['table'], $column['name'], $type);
         } else {
             $this->map[$index++] = array(0, $column['name'], $type);
         }
     }
 }
開發者ID:rizki96,項目名稱:HipHop,代碼行數:28,代碼來源:HpMysql.php

示例12: findDuplicates

 /**
  * Finds duplicate columns in select statement
  * @param  \PDOStatement
  * @return string
  */
 public static function findDuplicates(\PDOStatement $statement)
 {
     $cols = [];
     for ($i = 0; $i < $statement->columnCount(); $i++) {
         $meta = $statement->getColumnMeta($i);
         $cols[$meta['name']][] = isset($meta['table']) ? $meta['table'] : '';
     }
     $duplicates = [];
     foreach ($cols as $name => $tables) {
         if (count($tables) > 1) {
             $tables = array_filter(array_unique($tables));
             $duplicates[] = "'{$name}'" . ($tables ? ' (from ' . implode(', ', $tables) . ')' : '');
         }
     }
     return implode(', ', $duplicates);
 }
開發者ID:nette,項目名稱:database,代碼行數:21,代碼來源:Helpers.php

示例13: _define_column_types

 /**
  * Define columns from result.
  *
  * @param \PDOStatement $result
  *
  * @return array
  */
 private function _define_column_types(\PDOStatement $result)
 {
     $columns = array();
     $intTypes = array('int', 'integer', 'long', 'tiny', 'smallint', 'int4');
     try {
         for ($i = 0; $i < $result->columnCount(); ++$i) {
             $meta = $result->getColumnMeta($i);
             if ($meta && $meta['name'] != '[]') {
                 $metaType = strtolower($meta['native_type']);
                 $pdoType = $meta['pdo_type'];
                 if (in_array($pdoType, array(\PDO::PARAM_STR, \PDO::PARAM_LOB))) {
                     $metaType = 'string';
                 } elseif (in_array($metaType, $intTypes)) {
                     $metaType = 'integer';
                 } elseif ($pdoType === \PDO::PARAM_NULL) {
                     $metaType = 'null';
                 }
                 $columns[$meta['name']] = $metaType;
             }
         }
     } catch (\PDOException $e) {
     }
     return $columns;
 }
開發者ID:realboard,項目名稱:dbinstance,代碼行數:31,代碼來源:Executor.php

示例14: getColumnMeta

 /**
  * @return void 
  */
 public function getColumnMeta($column = 0)
 {
     $this->execute();
     return parent::getColumnMeta($column);
 }
開發者ID:mirkoargentino,項目名稱:bbn,代碼行數:8,代碼來源:query.php

示例15: getColumnMeta

 /**
  * @param $column
  * @return array
  */
 public function getColumnMeta($column)
 {
     $archLog = array('method' => 'PDOStatement::getColumnMeta', 'input' => array('column' => $column), 'output' => $this->PDOStatement->getColumnMeta($column), 'pointer' => $this->assignPointerString());
     return self::setLogReturnOutput($archLog);
 }
開發者ID:AdrianTrainorPHP,項目名稱:QueryScanner,代碼行數:9,代碼來源:ArchPDOStatement.php


注:本文中的PDOStatement::getColumnMeta方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。