PHP & MySQL on Mac OS X: Access denied for GUI user

Posted by Eirik Lillebo on Server Fault See other posts from Server Fault or by Eirik Lillebo
Published on 2009-07-30T15:39:22Z Indexed on 2010/03/25 3:03 UTC
Read the original article Hit count: 487

Filed under:
|
|
|

Hey!

This question was first posted to Stack Overflow, but as it is perhaps just as much a server issue I though it might be just as well to post it here also.

I have just installed and configured Apache, MySQL, PHP and phpMyAdmin on my Macbook in order to have a local development environment. But after I moved one of my projects over to the local server I get a weird MySQL error from one of my calls to mysql_query():

Access denied for user '_securityagent'@'localhost' (using password: NO)

First of all, the query I'm sending to MySQL is all valid, and I've even testet it through phpMyAdmin with perfect result. Secondly, the error message only happens here while I have at least 4 other mysql connections and queries per page. This call to mysql_query() happens at the end of a really long function that handles data for newly created or modified articles. This basically what it does:

  1. Collect all the data from article form (title, content, dates, etc..)
  2. Validate collected data
  3. Connect to database
  4. Dynamically build SQL query based on validated article data
  5. Send query to database before closing the connection

Pretty basic, I know. I did not recognize the username "_securityagent" so after a quick search I came across this from and article at Apple's Developer Connection talking about some random bug:

Mac OS X's security infrastructure gets around this problem by running its GUI code as a special user, "_securityagent".

Then I tried put a var_dump() on all variables used in the mysql_connect() call, and every time it returns the correct values (where username is not "_securityagent" of course). Thus I'm wondering if anyone has any idea why 'securityagent' is trying to connect to my database - and how I can keep this error from occurring when I call mysql_query().

Update: Here is the exact code I'm using to connect to the database. But a little explanation must follow:

  1. The connection error happens at a call to mysql_query() in function X in class_1
  2. class_1 uses class_2 to connect to database
  3. class_2 reads a config file with the database connection variables (host, user, pass, db)
  4. class_2 connect to the database through the following function:

var $SYSTEM_DB_HOST = "";

function connect_db() {

// Reads the config file
include('system_config.php');

if (!($SYSTEM_DB_HOST == "")) {
	mysql_connect($SYSTEM_DB_HOST, $SYSTEM_DB_USER, $SYSTEM_DB_PASS);
	@mysql_select_db($SYSTEM_DB);

	return true;
} else {
	return false;
}
}

© Server Fault or respective owner

Related posts about apache

Related posts about php