本文整理汇总了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;
}
示例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;
}
}
示例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());
}
}
示例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);
}
示例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;
}
示例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']];
}
}
}
示例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;
}
示例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'];
}
}
}
}
示例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;
}
示例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();
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例14: getColumnMeta
/**
* @return void
*/
public function getColumnMeta($column = 0)
{
$this->execute();
return parent::getColumnMeta($column);
}
示例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);
}