using a variable to show MYSQL_BOTH in mysql_fetch_array()

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
uberdragon
Forum Newbie
Posts: 11
Joined: Thu Apr 27, 2006 8:54 am
Location: Farmington, CT

using a variable to show MYSQL_BOTH in mysql_fetch_array()

Post by uberdragon »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello everyone, I am writing a custom database wrapper class that will allow for connecting to multiple databases (MSSQL, MySQL, ODBC, etc).

Code: Select all

if($type == 1) {//return array as both number and associative indices
				$return_type = $this->db_return_both;
			}
			echo "HERE! : $return_type $this->db_fetch_array $this->query_id <hr>";

			$row=call_user_func($this->db_fetch_array,$this->query_id,$return_type);
			return $row;
Please assume everything outside of this code snippet works properly (since it does). I want to allow a way for the developer to determine what type of indices to use on the return array from a fetch.

The output from this section is:

Code: Select all

HERE! : MYSQL_BOTH mysql_fetch_array Resource id #3
Warning: mysql_fetch_array(): The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH.
Which brings me to my question. How come in my echo statement, I can see that $return_type is set to MYSQL_BOTH but when I try to pass that along my call_user_func() it errors saying it is not a valid type?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

MYSQL_BOTH is not a string, it's a constant. It shouldn't output "MYSQL_BOTH" if it's correctly set. It should echo "3."

Which would ultimately mean that the code beyond that snippet does have an error. :wink:
User avatar
uberdragon
Forum Newbie
Posts: 11
Joined: Thu Apr 27, 2006 8:54 am
Location: Farmington, CT

Post by uberdragon »

ack.. too many hours of coding.. lol

Thanks for stating the obvious.. :D I needed it obviously ;)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

:lol:

Most people don't assume that all of their code works except for one small part. 8)
Just had to throw it out there. :wink:
Post Reply