programming.name Posted May 19, 2010 Share Posted May 19, 2010 Hi, Is there any way to get field names in ObJect oriented way? The following code doesn't work: (it returns integers rather than field names in string) $db_conn = new MySQLi('localhost', 'root', '' 'db'); $query = "SELECT * FROM user"; $result = $db_conn->query($query); $field_count = $result->field_count; for($index = 0 ; $index < $field_count; $index++) echo mysql_field_name($result, $index); Thanks. Link to comment https://forums.phpfreaks.com/topic/202252-getting-a-field-name-in-an-object-oriented-way/ Share on other sites More sharing options...
programming.name Posted May 19, 2010 Author Share Posted May 19, 2010 The answer was in the php dot net. I just found the answer by myself. if ($result = $mysqli->query($query)) { /* Get field information for 2nd column */ $result->field_seek(1); $finfo = $result->fetch_field(); printf("Name: %s\n", $finfo->name); printf("Table: %s\n", $finfo->table); printf("max. Len: %d\n", $finfo->max_length); printf("Flags: %d\n", $finfo->flags); printf("Type: %d\n\n", $finfo->type); $result->close(); } Link to comment https://forums.phpfreaks.com/topic/202252-getting-a-field-name-in-an-object-oriented-way/#findComment-1060544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.