Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 01-21-2007, 12:49 PM
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Posts: 393
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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 01-21-2007, 05:53 PM
thincom2000 thincom2000 is offline
 
Join Date: May 2006
Location: Bronx, NY
Posts: 1,205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 01-21-2007, 05:56 PM
Guest190829
Guest
 
Posts: n/a
Default

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?
Reply With Quote
  #4  
Old 01-21-2007, 07:09 PM
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Posts: 393
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 01-21-2007, 07:10 PM
Kentaurus's Avatar
Kentaurus Kentaurus is offline
 
Join Date: Dec 2001
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Quote:
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
Reply With Quote
  #6  
Old 01-21-2007, 07:13 PM
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Posts: 393
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 01-21-2007, 08:14 PM
Kentaurus's Avatar
Kentaurus Kentaurus is offline
 
Join Date: Dec 2001
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Correct Or rename the columns in your query. Both strategies are fine.
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:45 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08938 seconds
  • Memory Usage 2,212KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (6)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete