|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-08-25 18:57 UTC] maillist at pnpitalia dot it
[2004-08-25 19:11 UTC] georg@php.net
[2004-08-25 19:32 UTC] maillist at pnpitalia dot it
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 08:00:02 2025 UTC |
Description: ------------ mysqli_fetch_field return an object like this (printed with print_r): stdClass Object ( [name] => username [orgname] => username [table] => utenti [orgtable] => utenti [def] => [max_length] => 0 [flags] => 16392 [type] => 253 [decimals] => 0 ) the property [max_length] should contain the lenght of the field. Often empty query (select * from utenti where id = -1) are used to retrieve the description of the query when u want to automatically generate a form to insert a record, so I think it's important that this function work also with this kind of query. My workaround for now is to open 2 recordset one selecting the first row of the table (SELECT ... WHERE 1 LIMIT 0,1) and the other with the right where clause. BTW in php 4.3.x and obviously with the mysql extension not mysqli it work well. Reproduce code: --------------- <?php // modified mysqli_fetch_field manual example $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "SELECT Name, SurfaceArea from Country where code = 'ZZZ' ORDER BY Code LIMIT 5"; if ($result = mysqli_query($link, $query)) { /* Get field information for all fields */ while ($finfo = mysqli_fetch_field($result)) { 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); } mysqli_free_result($result); } /* close connection */ mysqli_close($link); ?>