PDOStatement::columnCount --
Returns the number of columns in the result set
Syntax
int PDOStatement::columnCount ( void )
Warning
This function is
EXPERIMENTAL. The behaviour of this function, the
name of this function, and anything else documented about this
function may change without notice in a future release of PHP.
Use this function at your own risk.
Use PDOStatement::columnCount() to return the number
of columns in the result set represented by the PDOStatement object.
If the PDOStatement object was returned from PDO::query(),
the column count is immediately available.
If the PDOStatement object was returned from
PDO::prepare(), an accurate column count will not be
available until you invoke PDOStatement::execute().
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
Example 1. Counting columns
This example demonstrates how PDOStatement::columnCount()
operates with and without a result set.
<?php $dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2');
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
/* Count the number of columns in the (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)
See Also
PDO::prepare()
PDOStatement::execute()
PDOStatement::rowCount()
Php pdostatement columncount Function syntax tag
pdostatement columncount php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online
Php pdostatement columncount syntax tutorial
php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.