当前位置: 首页>>代码示例>>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;未经允许,请勿转载。