mellis95 Posted February 3, 2010 Share Posted February 3, 2010 I am fairly new to PDO and am having trouble converting a script to work properly. Here is a script I found to create a dynamic table: function display_db_query($query_string, $connection, $header_bool, $table_params) { // perform the database query $result_id = mysql_query($query_string, $connection) or die("display_db_query:" . mysql_error()); // find out the number of columns in result $column_count = mysql_num_fields($result_id) or die("display_db_query:" . mysql_error()); // Here the table attributes from the $table_params variable are added print("<TABLE $table_params >\n"); // optionally print a bold header at top of table if ($header_bool) { print("<TR>"); for ($column_num = 0; $column_num < $column_count; $column_num++) { $field_name = mysql_field_name($result_id, $column_num); print("<TH>$field_name</TH>"); } print("</TR>\n"); } // print the body of the table while ($row = mysql_fetch_row($result_id)) { print("<TR ALIGN=LEFT VALIGN=TOP>"); for ($column_num = 0; $column_num < $column_count; $column_num++) { print("<TD>$row[$column_num]</TD>\n"); } print("</TR>\n"); } print("</TABLE>\n"); } This is the line I am having trouble with: $field_name = mysql_field_name($result_id, $column_num); What is the PDO equivalent/method of mysql_field_name in this case? Forgive me if this is basic, but I have been searching Google for about 30 minutes with nothing to show. Thanks in advance. Matt Quote Link to comment https://forums.phpfreaks.com/topic/190835-converting-a-script-to-pdo/ Share on other sites More sharing options...
Mchl Posted February 3, 2010 Share Posted February 3, 2010 Try browsing around php.net next time. You might try this http://www.php.net/manual/en/pdostatement.getcolumnmeta.php Quote Link to comment https://forums.phpfreaks.com/topic/190835-converting-a-script-to-pdo/#findComment-1006373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.