In the following code I get output that tells me that current user is myuser@%
and then second query will give me an error saying myuser@localhost
was denied INSERT permission.
$query = "SELECT CURRENT_USER();"
$result = mysql_query($query);
if(mysql_num_rows($result))
{
$data = mysql_fetch_assoc($result);
echo(" current user - ". $data['CURRENT_USER()'] . "
"); //current user - myuser@%
}
$query = "INSERT INTO DIFF_DATABASE.HISTORY (DATA) VALUES (\"" . $data. "\")";
if(mysql_query($query) == false)
{
echo(mysql_error()); // INSERT command denied to user 'myuser'@'localhost' for table 'HISTORY'
}
It looks like there is a switch of MySQL user from myuser@%
to myuser@localhost
How does this happen? I'm guessing this is because I'm selecting from a different database in the second query.