本文整理汇总了PHP中PDOStatement::columnCount方法的典型用法代码示例。如果您正苦于以下问题:PHP PDOStatement::columnCount方法的具体用法?PHP PDOStatement::columnCount怎么用?PHP PDOStatement::columnCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDOStatement
的用法示例。
在下文中一共展示了PDOStatement::columnCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init(&$pdoStmnt, $removePagingEnable = false)
{
$this->_pdoStmnt =& $pdoStmnt;
$this->_removePagingEnable = $removePagingEnable;
$this->_colCount = $this->_pdoStmnt->columnCount();
//$this->_rowCount = $this->_pdoStmnt->rowCount();
$this->_rowCount = 0;
return $this;
}
示例2: query
public function query($sql, $noexcept = false, $params = array())
{
if (!$noexcept) {
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
$this->statement = $this->connection->prepare($sql);
$result = false;
$time_start = microtime(true);
try {
if ($this->statement && $this->statement->execute($params)) {
$data = array();
if ($this->statement->columnCount()) {
while ($row = $this->statement->fetch(PDO::FETCH_ASSOC)) {
$data[] = $row;
}
$result = new stdClass();
$result->row = isset($data[0]) ? $data[0] : array();
$result->rows = $data;
$result->num_rows = $this->statement->rowCount();
}
}
} catch (PDOException $e) {
$this->error = 'SQL Error: ' . $e->getMessage() . '<br />Error No: ' . $e->getCode() . '<br />SQL:' . $sql;
if ($noexcept) {
return false;
} else {
throw new AException(AC_ERR_MYSQL, $this->error);
}
}
$time_exec = microtime(true) - $time_start;
// to avoid debug class init while setting was not yet loaded
if ($this->registry->get('config')) {
if ($this->registry->get('config')->has('config_debug')) {
$backtrace = debug_backtrace();
ADebug::set_query($sql, $time_exec, $backtrace[2]);
}
}
if ($result) {
return $result;
} else {
$result = new stdClass();
$result->row = array();
$result->rows = array();
$result->num_rows = 0;
return $result;
}
}
示例3: getLastColumnCount
/**
* @return int
*/
public function getLastColumnCount()
{
if (!$this->lastPdoStatement) {
return null;
}
return $this->lastPdoStatement->columnCount();
}
示例4: columnCount
public function columnCount()
{
if ($this->_statement instanceof \PDOStatement) {
return $this->_statement->columnCount();
}
return 0;
}
示例5: columnCount
/**
* Returns the number of columns in the result set.
* Returns null if the statement has no result set metadata.
*
* @return int The number of columns.
* @throws Zend_Db_Statement_Exception
*/
public function columnCount()
{
try {
return $this->_stmt->columnCount();
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage());
}
}
示例6: 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;
}
示例7: 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']];
}
}
}
示例8: query
/**
* returns sets result set from query
* @param string $sql
* @param array $bindValues
* @return \ErrorObject|boolean
*/
public function query($sql, array $bindValues)
{
$this->stmt = $this->pdoConn->prepare($sql);
try {
$this->stmt->execute($bindValues);
} catch (PDOException $e) {
$errorObject = new ErrorObject($e->getCode(), $e->getMessage(), $e->getTrace(), $_SERVER['SCRIPT_FILENAME']);
return $errorObject;
}
if ($this->stmt->columnCount() > 0) {
$this->resultSet = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
} else {
$this->lastInserted = $this->pdoConn->lastInsertId();
$this->numRows = $this->stmt->rowCount();
}
unset($this->stmt);
unset($this->pdoConn);
return true;
}
示例9: 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;
}
示例10: getMoreResults
public function getMoreResults()
{
$this->checkClosed();
$this->stmt->nextRowset();
$this->resultSet = null;
$this->updateCount = -1;
if ($this->stmt->columnCount() == 0) {
$this->updateCount = $this->stmt->rowCount();
return false;
}
return true;
}
示例11: getColumnsMeta
/**
* Returns metadata for all columns in a result set.
*
* @return array
* @throws DibiException
*/
public function getColumnsMeta()
{
$count = $this->resultSet->columnCount();
$meta = array();
for ($i = 0; $i < $count; $i++) {
// items 'name' and 'table' are required
$info = @$this->resultSet->getColumnsMeta($i);
// intentionally @
if ($info === FALSE) {
throw new DibiDriverException('Driver does not support meta data.');
}
$meta[] = $info;
}
return $meta;
}
示例12: fetch
/**
* @inheritDoc
*/
public function fetch()
{
$data = $this->pdoStatement ? $this->pdoStatement->fetch() : NULL;
if (!$data) {
$this->pdoStatement->closeCursor();
return FALSE;
}
$row = new Row();
foreach ($this->normalizeRow($data) as $key => $value) {
$row->{$key} = $value;
}
if ($this->result === NULL && count($data) !== $this->pdoStatement->columnCount()) {
trigger_error('Found duplicate columns in database result set.', E_USER_NOTICE);
}
$this->resultKey++;
return $this->result = $row;
}
示例13: __construct
public function __construct(PDOStatement $statement, $param_values = array(), $param_data_types = array(), $fetch_style = moojon_db::FETCH_ASSOC)
{
$this->iterator = $this->getIterator();
$query_string = $statement->queryString;
$log = $query_string;
if (ENVIRONMENT == 'development' || ENVIRONMENT == 'cli') {
$values = 'Param values(';
$parsed_query = $log;
foreach ($param_values as $key => $value) {
$values .= "{$key} = {$value}, ";
$apos = array_key_exists($key, $param_data_types) && $param_data_types[$key] == moojon_db::PARAM_STR ? "'" : '';
$parsed_query = str_replace($key, "{$apos}{$value}{$apos}", $parsed_query);
}
$parsed_query = "Parsed query: {$parsed_query}";
if (count($param_values)) {
$values = substr($values, 0, -2);
}
$values .= ')';
$data_types = 'Param data types(';
foreach ($param_data_types as $key => $value) {
$data_types .= "{$key} = {$value}, ";
}
if (count($data_types)) {
$data_types = substr($data_types, 0, -2);
}
$data_types .= ')';
$log .= "\n\n{$parsed_query}\n\n{$values}\n\n{$data_types}";
moojon_base::log($log);
}
foreach ($param_values as $key => $value) {
if ($value !== null) {
$data_type = array_key_exists($key, $param_data_types) ? $param_data_types[$key] : moojon_db::PARAM_STR;
if (strpos($query_string, $key) !== false) {
$statement->bindValue($key, $value, $data_type);
}
}
}
$this->affected = $statement->execute();
$this->non_query = $statement->columnCount() > 0;
if ($this->non_query) {
foreach ($statement->fetchAll($fetch_style) as $record) {
$this[] = $record;
}
}
}
示例14: 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);
}
}
}
示例15: execStatement
/**
* execute a previously bounded $stmt
*
* @param \PDOStatement $stmt should already have been passed through {@link bindStatement()}
* @return mixed boolean if the statement is something like INSERT, DELETE, or UPDATE, the result
* set if statement is SELECT
*/
protected function execStatement(PDOStatement $stmt)
{
$ret_mixed = false;
try {
if ($stmt->execute()) {
$col_count = $stmt->columnCount();
if ($col_count === 1) {
$ret_mixed = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
} else {
if ($col_count === 0) {
$ret_mixed = true;
} else {
$ret_mixed = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
//if/else
} else {
// error stuff? I'm actually not sure this will ever execute
///$arr = $stmt->errorInfo();
///\out::e($arr);
///\out::e($stmt->errorCode());
///$db = $this->getDb();
///\out::e($db->errorInfo());
///\out::e($db->errorCode());
}
//if/else
$stmt->closeCursor();
} catch (Exception $e) {
$stmt->closeCursor();
throw $e;
}
//try/catch
return $ret_mixed;
}