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 03-17-2005, 08:20 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default FAQ: What you need to know about running queries.

Sometimes you will need to run a query. Running a query is done to change the data in one of the tables in your database, or to change the strusture of the database like adding a table or adding a column to a table.

There are many different qys a query can be ran manually, some of them are:
  • Using a Server Panel Tool like phpMyAdmin. See for specifics on using phpMyAdmin: Running a Query using phpMyAdmin
  • Running the character based mysql client on a SSH/Telnet connection.
  • Using the buildin functionallity of your AdminCP
I will focus on the use of the AdminCP possibility in this FAQ.

How to get started running queries from AdminCP.
Before you will be able execute queries from your AdminCP you need to setup permissions for yourself to do so. Permission to execute a query from AdminCP is granted through your "includes/config.php" file.

In this file find the line that start with:
PHP Code:
$canrunqueries 
Behind the equal sign you will find a list of userid's seperated by a comma for those who have permission to execute queries from AdminCP. Add your own userid to this list.

Starting the SQL Tool in AdminCP
To start the Query tool login to your AdminCP->Import & Maintenance->Execute SQL Query
You will see a page with the following fields:
  • Automatic Query - Here you can select one of the predefined queries to manage some of the memberdata.
  • Manual Query - In this field you can enter a manual Query statement. This is where you will be doing most of your custom Query statements. Mind you that there can only be a single statement processed at a time.
  • Results to Show Per Page - Here you can set how many result lines you want to show on a page, if you are running a query that output information.
After you selected an Automatic Query or entered a Manual Query statement, you press Continue to execute the selection. If you are submitting a query that change things in your database, you will first receive a warning before the statement is really executed.

Table Prefix
A lot of times you will find instructions to replace a Table Prefix before running a query. The Table Prefix is defined in your "includes/config.php" with the line:
PHP Code:
$tableprefix ''
If there is nothing between the quotes, you are using an empty Table Prefix (i.e. no prefix), otherwise the text between the quotes is your Table Prefix.

If you are using a Table Prefix, all tablenames in your database will be prefixed with this string.
Example, if you are using an empty Table Prefix, the 'user' table will be named 'user' in the database. If you are using the Table Prefix 'vb3_', then that same table would be named 'vb3_user'.

Table Prefixes are normal only used if you need to load more then one instance of vBulletin into a single database, or if there might be naming conflicts with another application that used the same database.

How to change Table Prefix when instructed to run a query
A lot of times you will be instructed to run a query like this:
[sql]SELECT * FROM _TABLE_PREFIX_user;[/sql]
In this case you would need to replace the '_TABLE_PREFIX_' with your Table Prefix. If you don't use a Table Prefix this means you would need to remove this text, otherwise replace it with the defined Table Prefix.

Example using no Table Prefix and when using the Table Prefix os 'vb3_', the upper would be one of the following:
[sql]SELECT * FROM user;
SELECT * FROM vb3_user;[/sql]

How to know where one statement ends and the next begin.
SQL Query statements always end with a semicolon ';'. If you are instructed to run multiple queries at a time, input each statement seperate in the Manual Query input box and press Continue.

Example instructions:
execute the follwing statements (EXAMPLE!):
[sql]UPDATE USER
SET email = 'funny@laughs.com'
WHERE userid = 2;
SELECT * FROM user;[/sql]
This example consist of 2 statements, each to be run after the other. First you would run:
[sql]UPDATE USER
SET email = 'funny@laughs.com'
WHERE userid = 2;[/sql]
After that is completed, you would run:
[sql]SELECT * FROM user;[/sql]



Sorry good movie with Angela Jolie on now, will continue tomorrow. All remarks are welcomed.
Reply With Quote
  #2  
Old 03-17-2005, 08:27 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
SQL Query statements always end with a semicolon ';'.
Note that when running queries individually in most clients, including, most importantly, vB's MySQL wrapper class, you do not need to include--and often should not include--the semicolon.
Reply With Quote
  #3  
Old 03-17-2005, 09:03 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

True that a lot of clients don't require the ending semicolon. Wasn't sure about vB's wrapper, but didn't know there where also clients where you should not use a closing semicolon.

Will do some test and update tomorrow.
Reply With Quote
  #4  
Old 02-28-2006, 04:40 PM
T3MEDIA T3MEDIA is offline
 
Join Date: Dec 2004
Posts: 944
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

how would I write a SQL querry to change custom profile field x to 1 or 2 (on or off) or what ever options there is for that custom profile field.

example... profile field 31 has changed it used to default at 'slow' (first option) now the field has 'really slow' 'slow' and 'normal' but you want to default everyone at 'normal' and let all new users start at 'really slow' (that is easy. just defalut that in c.p.f manager)

the reseting is the confusing part for me.
Reply With Quote
  #5  
Old 02-28-2006, 04:59 PM
tehste tehste is offline
 
Join Date: Feb 2004
Posts: 221
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

oooh...
UPDATE _prefix_userfield SET field31='normal' WHERE field31='slow'
(no guarantees)
Reply With Quote
  #6  
Old 02-28-2006, 05:06 PM
Reeve of shinra's Avatar
Reeve of shinra Reeve of shinra is offline
 
Join Date: Oct 2001
Location: NYC
Posts: 1,896
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've noticed that vbulletin itself and certain hacks have a way of automatically specificing the table prefix in variables... can you share an example of that.

Like if $foo = user;
What would be the be the right way of writing
$foo = _table_prefix_user;
Reply With Quote
  #7  
Old 02-28-2006, 05:30 PM
tehste tehste is offline
 
Join Date: Feb 2004
Posts: 221
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I dont think you can use TABLE_PREFIX in the queries (least not in PhpMyAdmin)
Maybe it would depend it the query thing in the ACP processes php which I don't think it does - hence the one query limit, which is a shame.
Reply With Quote
  #8  
Old 03-01-2006, 05:48 PM
T3MEDIA T3MEDIA is offline
 
Join Date: Dec 2004
Posts: 944
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by tehste
oooh...
UPDATE _prefix_userfield SET field31='normal' WHERE field31='slow'
(no guarantees)
Sweet thanks now I can adjust my profiles. You know I was told from (someone else) that to do this was a hack...

wow.

Thanks tehste.
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 06:42 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.06857 seconds
  • Memory Usage 2,247KB
  • 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
  • (2)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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