tags:

views:

443

answers:

2

Hello All..

My setup: Ubuntu LAMP, application built w/ zend framework

My Problem: I have a few php scripts that I trigger via cron - daily email reports, rrd data capture etc.. I launch them via a cronjob like 'php -f scriptname.php'.
When I test the scripts from the commandline, logged in as myself, everything works fine. However, when the same script executes as root (via cron OR sudo) it fails with the following errors.

Warning: Access denied for user 'root'@'localhost'
Warning: mysql_real_escape_string(): A link to the server could not be established ...

I've done some research and I'm fairly sure that Im establishing a connection to mysql ahead of time, although the process is a bit obfuscated because Im working with the zend framework- Bootstrap class calls zend_db which calls registry class for the db credentials. and so on.

I've discovered one workaround: 'sudo -u myusername php -f scriptname.php' but I'd really like to know what Im doing wrong here..

TIA!

+2  A: 
Warning: Access denied for user 'root'@'localhost'

This is the message you get when you login to mysql server with the wrong username and password, or you log in from a location you are not allowed. Check that root can log in from the host 'localhost' and that it has sufficient permissions for your database and the mysql database.

'sudo -u myusername php -f scriptname.php'

Maybe Zend is taking your sysem level user id and expecting to log into mysql with that? can you check or override the credentials that zend is using to connect to mysql?

Question Mark
Thanks for the prompt replies.. I have three updates:1) The full error: Warning: mysql_real_escape_string(): Access denied for user 'root'@'localhost' (using password: NO) 2) There are many other queries in the script that work, only mysql_real_escape_string() does not. I am not passing a db connector parameter to mysql_escape_string becuase I (perhaps incorrectly) assumed that the connection was already created3) My system username is 'todd'. There is no mysql user 'todd' so the script must be pulling valid mysql credentials at some point?
ispytodd
mysql_real_escape_string must have a mysql resource passed in as well as the string your escaping. "using password: NO" makes me think (more) that it is trying a last ditch attempt at a connection and defaulting to root.
Question Mark
A: 

Thanks for your time guys. Through trial and error I have determined that the error is related to my Zend Framework implementation. My bootstrap, db initalization, registry.. who knows.

While I love working with the ZF, simple issues like this turn into huge time vampires. All Im looking for is a mysql_connect() somewhere! I'll update when I find something.

Much Thanks..

ispytodd
Apparently Zend framework recommends it's own $db->quote() method, which will taylor quoting and escaping to whatever db type you use. portable, yes.. annoying, yes! thanks all.
ispytodd