Jump to content

Getting a field name in an Object Oriented way


Recommended Posts

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.

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();
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.