Thanks guys for all your help!
I managed to finally work this out. What I did was make a function (setSettings()) to write the database information to a new file on the server called 'config.php' and made another function (getSettings()) that reads that file and puts the configuration information in an array, then returns that array. Here are the functions for anyone else who might need them:
class CMS{
var $dbSettings;
public function setSettings($dbhost, $dbuser, $dbpass, $dbname){
$handle = fopen('config.php','w+');
if($handle){
$output = "<?php
// Define database variables
\$DBHOST = '".$dbhost."';
\$DBUSER = '".$dbuser."';
\$DBPASS = '".$dbpass."';
\$DBNAME = '".$dbname."';
?>";
if(!fwrite($handle, $output)){
die("Could not write to file ".$handle.". Please try again later.");
}
}
fclose($handle);
}
public function getSettings(){
$handle = fopen('config.php','r');
while(!feof($handle)){
$line = trim(fgets($handle));
$line = explode("$", $line);
$line = explode("=", $line[1]);
if(($line[0] != '')||($line[1] != '')){
$variable = trim($line[0]);
$value = trim(substr($line[1],2,-2));
$this->dbSettings[$variable] = $value;
}
}
fclose($handle);
return $this->dbSettings;
}
Example:
$cms = new CMS();
$cms->setSettings('localhost','mrmicripper','my_pass','my_db')
$settings = $cms->getSettings();
echo $settings['DBHOST']; //Returns localhost
echo $settings['DBNAME']; //Returns my_db
Thanks for all your help, and I hope this code could help someone else as well.
MrMicRipper