Hi,
I'm pretty new to php and I have this problem I just can't fix. On my local machine (apache, php 4.3.4 and mysql) i've created this dbConnect.php script which reads in the db parameters (username, pwd, ...) and creates a connection with the DB.
In other scripts where i execute some queries, i have a require_once('dbConncect.php').
This works perfectly on my local machine, but when I load it to the internet, I get this error: "DB Error: insufficient permissions"
I don't want to put DB connection statements in every php file where I execute some queries.
Thanks for your help.
Below you can find the dbConnect.php code:
<?php
require_once('DB.php');
# read in the ini file
$inifile = "config/inifile.ini";
$filehandle = fopen($inifile, "r") or die("Error while opening ini file.");
while(!feof($filehandle)) {
# read in one line
$line = fgets($filehandle, 1024);
# get the parameters from the inifile contents
$arr = explode("=",$line);
for ($i=0; $i<count($arr);$i+=2){
if ($arr[$i] = "dbname"){
$dbname = $arr[$i+1];
}
elseif($arr[$i] = "dbhost"){
$host = $arr[$i+1];
}
elseif($arr[$i] = "dbusr"){
$usrname = $arr[$i+1];
}
elseif($arr[$i] = "dbpwd"){
$pwd = $arr[$i+1];
}
}
}
fclose($filehandle);
# create the connect string
$connect = "mysql://$usrname:$pwd@$host/$dbname";
# establish the connection
$db = DB::connect($connect);
if (DB::iserror($db) ){
die ($db->getMessage());
}
?>
I'm pretty new to php and I have this problem I just can't fix. On my local machine (apache, php 4.3.4 and mysql) i've created this dbConnect.php script which reads in the db parameters (username, pwd, ...) and creates a connection with the DB.
In other scripts where i execute some queries, i have a require_once('dbConncect.php').
This works perfectly on my local machine, but when I load it to the internet, I get this error: "DB Error: insufficient permissions"
I don't want to put DB connection statements in every php file where I execute some queries.
Thanks for your help.
Below you can find the dbConnect.php code:
<?php
require_once('DB.php');
# read in the ini file
$inifile = "config/inifile.ini";
$filehandle = fopen($inifile, "r") or die("Error while opening ini file.");
while(!feof($filehandle)) {
# read in one line
$line = fgets($filehandle, 1024);
# get the parameters from the inifile contents
$arr = explode("=",$line);
for ($i=0; $i<count($arr);$i+=2){
if ($arr[$i] = "dbname"){
$dbname = $arr[$i+1];
}
elseif($arr[$i] = "dbhost"){
$host = $arr[$i+1];
}
elseif($arr[$i] = "dbusr"){
$usrname = $arr[$i+1];
}
elseif($arr[$i] = "dbpwd"){
$pwd = $arr[$i+1];
}
}
}
fclose($filehandle);
# create the connect string
$connect = "mysql://$usrname:$pwd@$host/$dbname";
# establish the connection
$db = DB::connect($connect);
if (DB::iserror($db) ){
die ($db->getMessage());
}
?>