vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Connecting to MySQL database? (https://vborg.vbsupport.ru/showthread.php?t=69744)

DJ RRebel 09-22-2004 06:59 PM

Connecting to MySQL database?
 
Heya guys ... I think I nee a bit of help here. I want to start a couple of hacks, but can't figure out the very basics of how vB connects to my database?

From what I've learned on my own, the way to connect is with a mysql_connect() or mysql_pconnect() function (which is better?). Since I can't find either anywhere, I'm assuming there's another method I'm not aware of.

That being said, I would think that whatever the command, it would use the $dbusername and $dbpassword variables set in the config.php file? Also that the $dbname variable would be used to identify the name of the database. I couldn't find any of these variables anywhere?


Is there really no need for this? Is there already some 'magical' (for lack of a better word .. lol) connection, and all I really need to do is use some 'require_once()' functions to include some vB page that has the connection info set into some usable variables already?

Or do I need to specify a connection command and a mysql_select_db($dbname); command? Followed by a:

$query_results = mysql_query("SELECT blablabla FROM table_xyz;");

Then use whatever HTML and various PHP looping/if/then statements needed, with the following to show what I wanted to show:

$rowdata = mysql_fetch_array($query_results);
echo htmlspecialchars(stripslashes($rowdata("column_nam e"));


Seems I've got the basics, but I'm not sure if it's all been set-up already in some way?

Anyhow ... any help getting me on track would be greatly appreciated !!! :) ... Hopefully I'll soon be able to add some quality hacks to this community !!! :)



Not sure if this is stuff already incorporated in vB that I can use, or just basic MySQL/PHP stuff ... feel free to move it to the PHP/MySQL forum if you feel it's more in that domain ... although I really hope there's something already incorporated into vB to access the database !!! lol

Thanks to all who take the time to get through this .. as you can see ... I'm slowly making progress !!! :)

Dan 09-22-2004 07:17 PM

the connection part is located in the global.php file and the config file from my knowledge so if you just include the global.php file in your new php page it should connect without anything else added.

Jolten 09-22-2004 08:02 PM

Include the global.php file as Dan posted then simply use $DB_Site-> to connect to your database.

DJ RRebel 09-22-2004 08:07 PM

cool ... Thanks TONS !!! :) ... so all I need to worry about after that is the particular querie and what to do with it? Like as follows?


$query_results = mysql_query("SELECT column_a, column_b, column_c FROM table_xyz;");

Then use whatever HTML and various PHP looping/if/then statements needed, with the following to show what I wanted to show:

$rowdata = mysql_fetch_array($query_results);
echo htmlspecialchars(stripslashes($rowdata("column_nam e"));

Zachery 09-22-2004 08:38 PM

Quote:

Originally Posted by DJ RRebel
cool ... Thanks TONS !!! :) ... so all I need to worry about after that is the particular querie and what to do with it? Like as follows?


$query_results = mysql_query("SELECT column_a, column_b, column_c FROM table_xyz;");

Then use whatever HTML and various PHP looping/if/then statements needed, with the following to show what I wanted to show:

$rowdata = mysql_fetch_array($query_results);
echo htmlspecialchars(stripslashes($rowdata("column_nam e"));

Your better off making anything you want to show on the page into a varible and then displaying that varible inside of a template.

DJ RRebel 09-23-2004 12:49 AM

I think I know what you're getting at ... but how would I go abouts doing that?

I'm fairly confident I know how to create a template (done it a couple of years ago). But how would I go abouts calling the template from the php file?

Let's say I have a file getfunkydata.php

In that file, I would have to have:

require_once(global.php);

then:

- Call a master template that starts the introduction of the page and the start of a table where my results will be placed, as well as calls the header/footer templates. Then:

$query_results = mysql_query("SELECT column_a, column_b, column_c FROM table_xyz;");

- Start a loop for 0 to mysql_num_rows($query_results). Then within the loop have


$rowdata = mysql_fetch_array($query_results);

$col_a = htmlspecialchars(stripslashes($rowdata("column_a") );
$col_b = htmlspecialchars(stripslashes($rowdata("column_b") );
$col_c = htmlspecialchars(stripslashes($rowdata("column_c") );

- A call to a row formating template (that I'll have to create) which would include:
<tr><td>$col_a</td><td>$col_b</td><td>$col_c</td></tr>




I'm not too sure how the php page interacts with or call the templates?

seems to me, the looping data is linked from the templates in several "_bits" sub-templates, but I'm not sure how that is controled via the php page?


Anyhow .. you guys are REALLY helpful ... I think I'm actually starting to see the light at the end of the tunnel here !!! :)

Zachery 09-23-2004 01:27 AM

Quote:

Originally Posted by DJ RRebel
I think I know what you're getting at ... but how would I go abouts doing that?

I'm fairly confident I know how to create a template (done it a couple of years ago). But how would I go abouts calling the template from the php file?

Let's say I have a file getfunkydata.php

In that file, I would have to have:

require_once(global.php);

then:

- Call a master template that starts the introduction of the page and the start of a table where my results will be placed, as well as calls the header/footer templates. Then:

$query_results = mysql_query("SELECT column_a, column_b, column_c FROM table_xyz;");

- Start a loop for 0 to mysql_num_rows($query_results). Then within the loop have


$rowdata = mysql_fetch_array($query_results);

$col_a = htmlspecialchars(stripslashes($rowdata("column_a") );
$col_b = htmlspecialchars(stripslashes($rowdata("column_b") );
$col_c = htmlspecialchars(stripslashes($rowdata("column_c") );

- A call to a row formating template (that I'll have to create) which would include:
<tr><td>$col_a</td><td>$col_b</td><td>$col_c</td></tr>




I'm not too sure how the php page interacts with or call the templates?

seems to me, the looping data is linked from the templates in several "_bits" sub-templates, but I'm not sure how that is controled via the php page?


Anyhow .. you guys are REALLY helpful ... I think I'm actually starting to see the light at the end of the tunnel here !!! :)

https://vborg.vbsupport.ru/showthread.php?t=59939

Read this :)


All times are GMT. The time now is 05:58 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01039 seconds
  • Memory Usage 1,735KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete