PDOStatement::columnCount |
-- Learning is not just about technology, but also about dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
PHP Tutorial
- PHP Tutorial
- PHP Introduction
- PHP Installation
- PHP Syntax
- PHP Variables
- PHP echo/print
- PHP EOF(heredoc)
- PHP Data Types
- PHP Type Comparison
- PHP Constants
- PHP String
- PHP Operators
- PHP If...Else
- PHP Switch
- PHP Arrays
- PHP Array Sorting
- PHP Superglobals
- PHP While Loop
- PHP For Loop
- PHP Functions
- PHP Magic Constants
- PHP Namespaces
- PHP OOP
- PHP Quiz
PHP Forms
- PHP Forms
- PHP Form Validation
- PHP Form - Required Fields
- PHP Form - Validate Email and URL
- PHP Complete Form Example
- PHP $_GET Variable
- PHP $_POST Variable
PHP Advanced
- PHP Multidimensional Arrays
- PHP Date
- PHP Includes
- PHP File
- PHP File Upload
- PHP Cookie
- PHP Session
- PHP E-mail
- PHP Secure E-mail
- PHP Error
- PHP Exception
- PHP Filters
- PHP Advanced Filters
- PHP JSON
PHP 7 New Features
PHP Database
- PHP MySQL Introduction
- PHP MySQL Connect
- PHP MySQL Create Database
- PHP MySQL Create Table
- PHP MySQL Insert Data
- PHP MySQL Insert Multiple
- PHP MySQL Prepared Statements
- PHP MySQL Select Data
- PHP MySQL Where
- PHP MySQL Order By
- PHP MySQL Update
- PHP MySQL Delete
- PHP ODBC
PHP XML
PHP and AJAX
PHP Reference
- PHP Array
- PHP Calendar
- PHP cURL
- PHP Date
- PHP Directory
- PHP Error
- PHP Filesystem
- PHP Filter
- PHP FTP
- PHP HTTP
- PHP Libxml
- PHP Mail
- PHP Math
- PHP Misc
- PHP MySQLi
- PHP PDO
- PHP SimpleXML
- PHP String
- PHP XML
- PHP Zip
- PHP Timezones
- PHP Image Processing
- PHP RESTful
- PHP PCRE
- PHP Available Functions
- PHP Composer
Explore Further
- Web Service
- Programming
- Development Tools
- Network Services
- Scripting Languages
- Software
- Computer Science
- Web Design & Development
- Programming Languages
- Scripts
PDOStatement::columnCount
PDOStatement::columnCount — Returns the number of columns in the result set. (PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)
Description
Syntax
int PDOStatement::columnCount ( void )
Use PDOStatement::columnCount() to return the number of columns in the result set represented by the PDOStatement object.
If the PDOStatement object was returned by PDO::query(), the column count is immediately available.
If the PDOStatement object was returned by PDO::prepare(), the column count cannot be accurately determined until PDOStatement::execute() is called.
Return Values
Returns the number of columns in the result set represented by the PDOStatement object. If there is no result set, PDOStatement::columnCount() returns 0.
Examples
Counting Columns
The following example demonstrates how to use PDOStatement::columnCount() on a result set and an empty set.
<?php
$dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2');
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
/* Count the number of columns in a (non-existent) result set */
$colcount = $sth->columnCount();
print("Before execute(), result set has $colcount columns (should be 0)n");
$sth->execute();
/* Count the number of columns in the result set */
$colcount = $sth->columnCount();
print("After execute(), result set has $colcount columns (should be 2)n");
?>
The above example will output:
Before execute(), result set has 0 columns (should be 0)
After execute(), result set has 2 columns (should be 2)
YouTip