ID: 29841 Updated by: [EMAIL PROTECTED] Reported By: maillist at pnpitalia dot it -Status: Open +Status: Bogus Bug Type: MySQL related Operating System: linux gentoo 3q2004 PHP Version: 5CVS-2004-08-25 (dev) New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php mysql(i)_fetch_field returns metadata information for resultset, not the tabledefinition. Same behaviour for ext/mysql (mysql_fetch_field) Previous Comments: ------------------------------------------------------------------------ [2004-08-25 18:57:02] maillist at pnpitalia dot it worst ... almost for varchar (type=253) field it *always* return the length of the string contained in the recordset . i.e. with the previous example: if used SELECT username WHERE username ="12345" [max_length] => 5 ------------------------------------------------------------------------ [2004-08-25 18:31:25] maillist at pnpitalia dot it 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); ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29841&edit=1
