Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-02-2007, 12:30 PM
mihai11 mihai11 is offline
 
Join Date: Dec 2005
Location: Sibiu - Romania
Posts: 199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Hardcoding in PHP versus SQL

Hi,

I have a list of about 10 categories that I need to display. Right now I have the categories in the database and I am using 1 SQL query to get them. I am thinking that I can hard-code the list of categories in PHP in order to avoid quering the database. The down side of this is that I need to update the list of categories in 2 places (in the database and in the PHP file) if I choose to add more categories in the future. The "bright side" of the "downside" is that the list of categories will be updated VERY rarely (possibly never).

What do you think of this ? Should I hard-code in PHP ?

Regards,
Razvan M.
Reply With Quote
  #2  
Old 08-02-2007, 01:22 PM
EnIgMa1234 EnIgMa1234 is offline
 
Join Date: Mar 2006
Location: .:: Ireland ::.
Posts: 1,306
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

One query isn't much of a differance if there's only 10 results. I'd go with SQL but thats just me.
Reply With Quote
  #3  
Old 08-02-2007, 01:30 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could consider storing the categories also as a serialised array in the datastore table. This would reduce the number of extra queries to 1 (which often can be combined with reading other datastore values).
Reply With Quote
  #4  
Old 08-02-2007, 01:37 PM
mihai11 mihai11 is offline
 
Join Date: Dec 2005
Location: Sibiu - Romania
Posts: 199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Marco van Herwaarden View Post
You could consider storing the categories also as a serialised array in the datastore table. This would reduce the number of extra queries to 1 (which often can be combined with reading other datastore values).
Hmm.... it is the first time that I look at the datastore table. Can you give me more information about it ? What is its purpose ? Maybe you have a link with relevant information.

Since I am not using datastore values anywhere else in my mod there is no advantage from this point of view: I mean, I am already using just 1 query to retrieve the results.

One more question: how do I serialize values to the datastore ? Is there some VB class to do this ?

Quote:
Originally Posted by EnIgMa1234 View Post
One query isn't much of a differance if there's only 10 results. I'd go with SQL but thats just me.
The problem is that the page that requires this query has many options (besides categories) and for each option I will need to fire this query. There will be many views ...

Maybe I should make the table storing this data of type MEMORY. Since it is very small there should be no problem here. Currently the storage engine is INNODB.
Reply With Quote
  #5  
Old 08-02-2007, 01:54 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

An in MEMORY (HEAP) table is cleared on each restart of the MySQL server and not suitable for permanent storage (hence why vB only uses HEAP for session tables).

You can find various articles that include information on how to use the datastore, one of them: Cache System Explanation (datastore)

PS Using the datastore can reduce the number of queries as vBulletin already read all needed rows from the table.
Reply With Quote
  #6  
Old 08-02-2007, 05:39 PM
mihai11 mihai11 is offline
 
Join Date: Dec 2005
Location: Sibiu - Romania
Posts: 199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Marco van Herwaarden View Post
An in MEMORY (HEAP) table is cleared on each restart of the MySQL server and not suitable for permanent storage (hence why vB only uses HEAP for session tables).

You can find various articles that include information on how to use the datastore, one of them: Cache System Explanation (datastore)

PS Using the datastore can reduce the number of queries as vBulletin already read all needed rows from the table.
What you suggested is the BEST solution. The relevant part is this:

Quote:
So instead of running a query everytime you want to get the drop down information, you just get it from the datastore and save that query.

Exactly what I was looking for. Thank you.
Reply With Quote
Reply


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 12:15 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.04157 seconds
  • Memory Usage 2,213KB
  • 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
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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