• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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