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


PHP PDOStatement::columnCount方法代碼示例

本文整理匯總了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;
 }
開發者ID:lajosbencz,項目名稱:pshd,代碼行數:9,代碼來源:Result.php

示例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;
     }
 }
開發者ID:siddht1,項目名稱:abantecart-src,代碼行數:48,代碼來源:apdomysql.php

示例3: getLastColumnCount

 /**
  * @return int
  */
 public function getLastColumnCount()
 {
     if (!$this->lastPdoStatement) {
         return null;
     }
     return $this->lastPdoStatement->columnCount();
 }
開發者ID:Jouy,項目名稱:domain-model-mapper,代碼行數:10,代碼來源:DbAdapter.php

示例4: columnCount

 public function columnCount()
 {
     if ($this->_statement instanceof \PDOStatement) {
         return $this->_statement->columnCount();
     }
     return 0;
 }
開發者ID:rtshome,項目名稱:pgbabylon,代碼行數:7,代碼來源:PDOStatement.php

示例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());
     }
 }
開發者ID:jorgenils,項目名稱:zend-framework,代碼行數:16,代碼來源:Pdo.php

示例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;
 }
開發者ID:atijust,項目名稱:mappa,代碼行數:13,代碼來源:Hydrator.php

示例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']];
         }
     }
 }
開發者ID:robo47,項目名稱:BlazeFramework,代碼行數:18,代碼來源:AbstractResultSet.php

示例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;
 }
開發者ID:eggmatters,項目名稱:eggmatters_com,代碼行數:25,代碼來源:PdoMysql.php

示例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;
 }
開發者ID:mpeshev,項目名稱:wp-db-driver,代碼行數:15,代碼來源:pdo_mysql.php

示例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;
 }
開發者ID:robo47,項目名稱:BlazeFramework,代碼行數:12,代碼來源:AbstractStatement.php

示例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;
 }
開發者ID:laiello,項目名稱:webuntucms,代碼行數:21,代碼來源:pdo.php

示例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;
 }
開發者ID:cujan,項目名稱:atlashornin,代碼行數:20,代碼來源:ResultSet.php

示例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;
         }
     }
 }
開發者ID:steview,項目名稱:moojon,代碼行數:45,代碼來源:moojon.query.result.class.php

示例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);
         }
     }
 }
開發者ID:rizki96,項目名稱:HipHop,代碼行數:28,代碼來源:HpMysql.php

示例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;
 }
開發者ID:Jaymon,項目名稱:Mingo,代碼行數:41,代碼來源:MingoPDOInterface.php


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