From: Prometheus Deckard
Bump
Okay, with the help of some friends, I've managed to get 'some' of this down, although I'm still not sure how to access a database via PHP. Any help would be appreciated

Well, you are in luck. I'm a PHP coder by trade. What you are asking for, I'm assuming, is how do you connect to a mySQL database through PHP.
If that is the case, I'll show ya. (just remember... you asked for it...)
Now. To start, you need the following.
mySQL Database Information:
- DB name
- username
- password
Now, please make note, I keep my DB access into in a separate file to keep it safe from prying eyes. I then include that info into the main page, checking for a constant variable. if the variable it not there, it breaks the process. You can conbine the files if you wish, but I do not reccomend it.
Also, please note. This is not a PHP class. It's just a basic example of what can be done and, hopefully, gives you something to work from.
Lets say you have a database called
sl_stuff Inside that db, you have a table called
keys The table keys has the following columns within it:
- key_id //The table row
- key_value //The key value
In this example, we only really care about the column key_value and the data stored within.
So, lets start with the db connection information:
Call this file db.php
<?php
if ( !defined('HACK_PROT') )
{
die("Hacking attempt");
}
/*------------------------------------------------------*\
Standard mySQL Connection strings
These sub-routines will be refferenced by all
scripts to access the mySQL dB.
\*------------------------------------------------------*/
/*------------------------------------------------------*\
Variable Definitions
\*------------------------------------------------------*/
$mysql_host;
$mysql_user;
$mysql_password;
$mysql_db;
/*------------------------------------------------------*\
User Set Variables
\*------------------------------------------------------*/
$mysql_host = "localhost";
$mysql_user = "USERNAME";
$mysql_password = "PASSWORD";
$mysql_db = "sl_stuff";
/*------------------------------------------------------*\
DO NOT Edit anything below this line unless you
EXACTLY what you are doing to the code!!!
\*------------------------------------------------------*/
// Connecting, selecting database
$sqlopen = mysql_connect($mysql_host, $mysql_user, $mysql_password)
or die("Could not connect: " . mysql_error());
mysql_select_db($mysql_db) or die("Could not select database");
?>
Just replace the access variables.
Now for the actual connection stuff.
Call this file anything you want. Me, I'd call it sl_stuff.php but that's just me:
<?php
define('HACK_PROT', TRUE);
define('DEBUG', TRUE);
$root_path = './';
include_once($root_path . 'db.php');
$sql = ("SELECT * FROM keys");
if ( DEBUG ) {echo "$sql\n\n";}
$sqlresult = mysql_query($sql) or die( mysql_error() );
while ($results = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) {
print ("$results[key_value]\n");
$SLkeys[] = $results[key_value];
}
That's pretty much it. All the contents of the DB will be printed out and stored into the array $SLkeys. Past here, you'll need to pull the data from the Array and process it.... something that is probably better done in a PHP specific forum.
I hope this helps and gets your off the ground.