• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

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