View Single Post
Old 05-10-2009, 10:57 AM   #4 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
That is the correct behaviour insofar as I can tell. You should really have a fetchRow and fetchAll function.

Having an ambiguous fetch function doesn't imply either one nor the other. That function would make a good fetchAll, but for a fetchRow, try using mysql_fetch_row and returning that.
On the contrary, the method in the first post would constitute a fetchRow if you wanted to distinguish the two: mysql_fetch_array/assoc/object only fetch one row at a time.

Quote:
Originally Posted by allworknoplay View Post
I am getting an odd behavior with my database class...
The behaviour is as expected, if you know what those mysql_fetch_* functions do. By default, mysql_fetch_array will return an array with both number and associative indices. If you only want the number indices, provide the MYSQL_NUM constant to optional second argument, $result_type. You can call the same function with MYSQL_ASSOC to have only associative indices returned.

As for your "ONE MORE THING...." with regards to counting the return value of your method. You are counting the number of array items returned. Since the array only holds one row, the count is twice the number of columns (since both number and associative indices are being returned) in the table, not the number of rows returned by the query.
Salathe is offline  
Reply With Quote