Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 21 Jan 2007, 13:49
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Real name: Tim Kaler
The difference between mysql_fetch_array and $db->fetch_array?

I have a script which works perfectly with mysql_fetch_array($result), however, when switching it to $db->fetch_array($result) it does not work. It does not give an error, it simply does not return a result.

Is there something fundamentally different between vbulletin's database class fetch_array and mysql_fetch_array?

(All other database class functions are working just fine... I have query_read within the same function and it works perfectly)
Reply With Quote
  #2  
Old 21 Jan 2007, 18:53
thincom2000 thincom2000 is offline
 
Join Date: Jun 2006
Real name: Ted
I read somewhere that $db->fetch_array() uses fewer resources than mysql_fetch_array() and mysql_fetch_assoc(), but I looked at the code in class_core.php recently, and I think I remember seeing that it was merely a difference of semantics.

Then again, I'm no expert.
Reply With Quote
  #3  
Old 21 Jan 2007, 18:56
Danny.VBT's Avatar
Danny.VBT Danny.VBT is offline
 
Join Date: Oct 2004
It is simply a wrapper to the mysql_fetch_array function. If you are programming a vBulletin modification, you should use $db->fetch_array() to follow vBulletin's coding standards.

Can you post the two lines of code with mysql_fetch_array and $db->fetch_array?
__________________
while($coffeeMachine->supply($Danny)) { $Danny->run(); }

Twitter Blog
Reply With Quote
  #4  
Old 21 Jan 2007, 20:09
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Real name: Tim Kaler
I actually was able to find a solution by using $db->fetch_row. The problem was that I was using numeric keys for certain result sets (which was something I would have prefered not to change because it was quite useful.)

Oddly enough $db->fetch_array does not appear to be fully inter-changable with mysql_fetch_array in this regard. But as I said $db->fetch_row worked perfectly in those specific cases.
Reply With Quote
  #5  
Old 21 Jan 2007, 20:10
Kentaurus's Avatar
Kentaurus Kentaurus is offline
 
Join Date: Dec 2001
Abstraction. Since $db->fetch_array is wrapper, if you changed your database, mysql version, implementation details or wanted to add extra behaviour, $db->fetch_array provides a way to do so, since all the code would use an abstraction and not the direct mysql code.

Meaning... it would be a best practice to use $db->fetch_array if you are coding for Vbulletin

Originally Posted by Attilitus View Post
I actually was able to find a solution by using $db->fetch_row. The problem was that I was using numeric keys for certain result sets (which was something I would have prefered not to change because it was quite useful.)

Oddly enough $db->fetch_array does not appear to be fully inter-changable with mysql_fetch_array in this regard.
It's actually the equivalent of calling:

mysql_fetch_array($result, MYSQL_ASSOC)

and not plain mysql_fetch_array
__________________
Try MySmilies Mod - User-based, custom smilies for each user

CemZoo.com - Anime Community
CemZoo Forums - Anime Forums

Last edited by Kentaurus : 21 Jan 2007 at 20:11. Reason: Automerged Doublepost
Reply With Quote
  #6  
Old 21 Jan 2007, 20:13
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Real name: Tim Kaler
Ha ha... I was never considering NOT using the vbulletin database class. I was just trying to find the right parameter that I needed. Certainly it is alright to use vbulletin's databaseclass function $db->fetch_row. Correct?
Reply With Quote
  #7  
Old 21 Jan 2007, 21:14
Kentaurus's Avatar
Kentaurus Kentaurus is offline
 
Join Date: Dec 2001
Correct Or rename the columns in your query. Both strategies are fine.
__________________
Try MySmilies Mod - User-based, custom smilies for each user

CemZoo.com - Anime Community
CemZoo Forums - Anime Forums
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 03:49.

Layout Options | Width: Wide Color: