How does pdo obtain all fields ?? At last, this post was edited by rainxies from 2013-03-11:08:21. I only found the mysql method. with pdo, how should I write the following code? Thank you $ result & nbsp ;=& nbsp; mysql_query ("SELECT & nbsp; * & n pdo how do I obtain all fields ??
At last, this post was edited by rainxies at 13:08:21. I only found the mysql method. if I use pdo, how should I write the following code? Thank you.
$result = mysql_query("SELECT * FROM table");
$fields = mysql_num_fields($result);
for ($i=0; $i < $fields; $i++) {
$names[] = mysql_field_name($result, $i);
}
print_r($names);
Mysql_num_fields I have found a columnCount () function under PDOStatement.
Mysql_field_name: I did not find the corresponding name .........
Is there another way ??
------ Solution --------------------
This post was last edited by xuzuning at 13:52:28
Try {
$ Dbh = new PDO ('MySQL: host = localhost; dbname = test', 'root ','');
$ Stmt = $ dbh-> query ("select * from tbl_name ");
For ($ I = 0; $ I <$ stmt-> columnCount (); $ I ++ ){
Echo $ stmt-> getColumnMeta ($ I) ['name'], PHP_EOL; // applicable to php5.4. the previous version should be split into two sentences.
}
} Catch (PDOException $ e ){
Die ("Error! : ". $ E-> getMessage ());
}