Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP and MySQL

Status
Not open for further replies.

TyzA

Programmer
Jan 7, 2002
86
0
0
BE
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());
}
?>
 
Insufficient data for a meaningful answer.

The error message you are posting must be generated by code you haven't posted.


Which PHP family of functions are you using to connect to MySQL?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 

Or - insufficient permissions makes me think of users who don't have permission to do the thing they are trying to do. Have yuou printed your connect string to make sure the username and password are what you think they should be when the string is constructed? And are you sure the user has permission to do whatever you're trying to do?
 
Unless the parameters you're using to pass to connect (username,password,db...) and privileges of the remote db are exactly the same as your local machine, it will not work.

Find out from your host the username, and password to connect to mysql.

[cheers]
Cheers!
Laura
 
Yep,
Youre right. for some reason the parameters from the ini file aren't read in correctly.
It works now.
Thanks for you're help guys & girls
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top