How does pdo obtain all fields? I only find the mysql method. if pdo is used, how can 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 ??
Reply to discussion (solution)
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 ());}
$ Sqlstr = "select * from table"
$ Sqlstr = "select * from table"
$ Sqlstr = "select * from table"; $ rerult = mysql_quer ($ sqlstr); while ($ field = mysql_fetch_field ($ result) {echo "$ field-> name ";}
Thanks to the moderator, I finally got it done. php is really unfamiliar !!!
This post was last edited by xuzuning at 13:52:28
PHP code? 123456789try {$ dbh = new PDO ('MySQL: host = localhost; dbname = test', 'root ',''); $ stmt = $ dbh-> query ("select * from tbl_na ......