Login   Register  
PHP Classes
elePHPant
Icontem

Small bug in the code

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Mysqli  >  All threads  >  Small bug in the code  >  (Un) Subscribe thread alerts  
Subject:Small bug in the code
Summary:Fails if you have a table with a field name of "i"
Messages:1
Author:Henry Hank
Date:2013-02-01 21:43:47
 

  1. Small bug in the code   Reply  
Picture of Henry Hank
Henry Hank
2013-02-01 21:43:47
This took a while to track down, since it appeared to be a bug in MySQL.

If there is table with a field name of just "i", the code in the function dbQuery will fail and return a truncated/corrupted result set.

The problem appears to be the $i loop variable counter and this line:

$result[$i][$field] = $$field;

If you just change the $i loop variable name to something that will not likely be any MySQL field name, the code again works. I changed it to $ixxx in three places in this one function.

I'm going to guess the same or similar thing will happen if you have fields named the same as any variable used in this function: args, query, smt, res, fields, result as the expression $$field will resolve to the local PHP variable name and not the MySQL field name intended (I'm not sure why that is the case).

As I said previously, this is a great set of functions/tools to get started with prepared statements, and I have depended on it extensively. Thank you for the code.