Database Reference
In-Depth Information
end
sth . finish
The program produces this output:
Statement: SELECT name, birth FROM profile
Number of columns: 2
--- Column 0 (name) ---
sql_type: 12
type_name: VARCHAR
precision: 20
scale: 0
nullable: false
indexed: false
primary: false
unique: false
mysql_type: 253
mysql_type_name: VARCHAR
mysql_length: 20
mysql_max_length: 7
mysql_flags: 4097
--- Column 1 (birth) ---
sql_type: 9
type_name: DATE
precision: 10
scale: 0
nullable: true
indexed: false
primary: false
unique: false
mysql_type: 10
mysql_type_name: DATE
mysql_length: 10
mysql_max_length: 10
mysql_flags: 128
To get a row count from a result set generated by calling execute , fetch the rows and
count them yourself. The sth.rows method is not guaranteed to work for result sets.
You can also obtain a result set by calling one of the DBI methods that uses a database
handle rather than a statement handle, such as select_one or select_all . These
methods provide no access to column metadata. That information already will have
been disposed of by the time the method returns, and is unavailable to your scripts.
However, you can derive column and row counts by examining the result set itself.
PHP
In PHP, metadata for SELECT statements is available from PDO after a successful call to
query() . If you execute a statement using prepare() plus execute() instead (which
can be used for SELECT or non- SELECT statements), metadata becomes available after
execute() .
Search WWH ::




Custom Search