From: maillist at pnpitalia dot it
Operating system: linux gentoo 3q2004
PHP version: 5CVS-2004-08-25 (dev)
PHP Bug Type: MySQL related
Bug description: mysqli_fetch_field wrong max_length w/ empty query
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 bug report at http://bugs.php.net/?id=29841&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29841&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=29841&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=29841&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=29841&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29841&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29841&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29841&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29841&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29841&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29841&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29841&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29841&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29841&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29841&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29841&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29841&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29841&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29841&r=float