The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
How to establish database connection for custom Page
Ok so I am creating a custom page, everything went well but am stuck on one little issue, that is how do i establish connection to database in vBulletin 4.x, I know how to establish database connection but I just want to know if their is any built in function in vbulletin 4.x that does the connection to establishment automatically. Below is my demo code, scroll down the the very bottom in red is where I showed a example where I said mysql_query($sql) but before I can do that I first need to connect to database. Anyone know the answer?
Quote:
|
#2
|
||||
|
||||
Since you included global.php, then you can just write the queries like they are written in the rest of the vb files - SQL Query Syntax
|
#3
|
|||
|
|||
ahhhh THANKS.... IT WORKS hahahaha.....
Oh and also for those of you who wants to know how to grab and fetch stuff from database then this is the code Before you can use the code below you first need to import global.php by doing require_once('./global.php'); $results = $db->query_read( "YOUR SQL QUERY GOES HERE" ); while($rows = $db->fetch_array($results)) { //This will walk through each row that is returned from $result and stored them in $rows on each walk through, if your query only returned 1 row results maximum then no need to put $rows = $db->detch_array($results) inside while loop } Hope the above code will help out some of you guys |
#4
|
|||
|
|||
Tip... if you know you are only looking for one result, you can use query_first instead of query_read
Code:
$info = $db->query_first("SELECT foo FROM table WHERE id = 5"); // $info['foo'] |
#5
|
|||
|
|||
Quote:
Also what about lets say query_read for example if I am grabbing a row with which contains more than one column, so say $info = $db->query_first("SELECT foo,moo,boo FROM table WHERE id = 5"); which selects foo,moo,boo where id=5 so can you do $info['foo'] $info['moo'] $info['boo'] to get those three column result or should you fetch_array first? |
#6
|
|||
|
|||
The query_first call would give you $info['foo'] and $info['moo']
and $info['boo'] without doing a fetch_array call. Example... Code:
$info = $db->query_first(" SELECT foo, moo, boo FROM table WHERE id = 5 "); if ($info) { echo $info['foo'] . ' ' . $info['moo'] . ' ' . $info['boo']; } else { echo 'bust'; } |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|