...

View Full Version : I'm looking for a PHP config.php guide



ogden2k
06-17-2006, 12:28 AM
I have a site that connects to a database on multiple pages and displays different data from different tables of that database. Right now, I have a $dbcnx command on every page, this is a little bit of a hassle. I'd like to create a config.php page that my front end pages will call.

How would I go about doing this? I cannot seem to find a guide. Thanks in advance.

fci
06-17-2006, 01:10 AM
create a file called config.php, put everything you want to be global inside of it, then in any page you want that information you just do

include 'config.php';

you can read about it here..
http://us3.php.net/include/

ogden2k
06-17-2006, 03:35 PM
I've just specified in the index file to include the config page

<? include('includes/config.php'); ?>
and in the config

// ****** DATABASE TYPE ******
$config['Database']['dbtype'] = 'mysql';

// ****** DATABASE NAME ******
$config['Database']['dbname'] = 'db';

// ****** MASTER DATABASE SERVER NAME AND PORT ******
$config['MasterServer']['servername'] = 'localhost';
$config['MasterServer']['port'] = 3306;

// ****** MASTER DATABASE USERNAME & PASSWORD ******
$config['MasterServer']['username'] = 'x';
$config['MasterServer']['password'] = 'x';

But, when I load index.php the table does not load. This is the code that pulls the table on index:

// Request the text of all the info
$result = @mysql_query('SELECT * FROM wanted');

if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each game in a row
while ($row = mysql_fetch_array($result)) {
echo '' . $row['title'] . ' (<em>' . $row['system'] . '</em>)<br />';
}
?>

GJay
06-17-2006, 05:25 PM
you still need to have the connection and db-selects somewhere...

ogden2k
06-17-2006, 06:36 PM
I read through the guide but it doesn't say how to do that.

fci
06-17-2006, 07:10 PM
call mysql_connect() in your config.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum