• Plesk Uservoice will be deprecated by October. Moving forward, all product feature requests and improvement suggestions will be managed through our new platform Plesk Productboard.
    To continue sharing your ideas and feedback, please visit features.plesk.com

php: subdomain error

R

Rached

Guest
Hi all, i would appreciate alot if any one can guide me through this issue.
In our VPS, i am hosting a domain.biz. I created subdomain.domain.biz and an ftp, mysql user for that account. I gave the subdomain mysqluser full privilleges on subdomaindB. In the subdomain.domain.biz i have a php file that connects to subdomaindB, with the hostname, dBname, username, and pass as global variables, now when i call a function inside the php file to connect to the dB, using these variables as parameters, i get:
"Access denied for user: 'apache@localhost' (Using password: YES)"
But if in the function, i use normal text as parameter, it works fine. Any idea ?

example (does not work):
<?php
$host="localhost";
$user="username";
$password="password";
$dbName = "subdomaindB";

function checkUser($userID)
{
$db = mysql_connect($host,$user,$password);
if (!$db) exit(mysql_error());
$w = mysql_select_db($dbName);
if (!$w) exit(mysql_error());
$sql = "";
$sql="any sql statement";
$result = mysql_query($sql,$db);
mysql_close();
$num_rows = mysql_num_rows($result);
mysql_free_result($result);
return $num_rows;
}
?>

example (this works)
<?php
$host="localhost";
$user="username";
$password="password";
$dbName = "subdomaindB";

function checkUser($userID)
{
$db = mysql_connect("localhost","username","password");
if (!$db) exit(mysql_error());
$w = mysql_select_db("subdomaindB");
if (!$w) exit(mysql_error());
$sql = "";
$sql="any sql statement";
$result = mysql_query($sql,$db);
mysql_close();
$num_rows = mysql_num_rows($result);
mysql_free_result($result);
return $num_rows;
}
?>
 
Back
Top