PHP scripts not connecting to mySQL DB on linux server 11.10
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I uploaded a php page to the server to test the connection with the mySQL DS but I keep getting can't connect from the script. This is what I have for the php script:
You need to get more info than just the "can't connect" from your own script, search the logs for apache, php & mysql.
One useful way is to open a few terminals and use "tail -f" on logs, like "tail -f /var/log/apache2/error.log" in one terminal, "tail -f /var/log/mysql.err" on second and so on (this on my Debian Lenny) while trying to connect.
You will then catch log messages in real-time.
A few other things to check:
Is mysql server running?
Can you log in to mysql in terminal with that password, can you access the database?
---
Edit:
I'm not very familiar with php, just wonder if you can have a blank before the value when assigning a variable?
Last edited by pingu; 01-21-2013 at 12:56 PM.
Reason: Thinking...
Run something like this
$host = "localhost";
$username = "root";
$password = "my root password";
mysql_connect($host, $username, $password) or die(mysql_error());
Ok the error I am getting now says Access denied for user 'root'@'localhost' (using password: YES). I also get that error in the apache log files and when trying to login to mysql through the terminal.
Did you create a root user password for mysql? Check the link below here at LQ. If you use the Search function on the top right of the page, you should be able to see numerous other posts here as this is a common problem.
Hey yancek thanks for the input, I checked out that thread and ran some of the querys and there are passwords listed for mysql root users. But I am still getting the Access denied for user 'root'@'localhost' (using password: YES) error when I am trying to connect to mysql through a php page.
Are you running the PHP on the same server as the MySQL database? I presume so since you used 'localhost'. Can you post the output of 'select user, host, password from mysql.user;'?
I use mysql_connect with a fourth parameter, the database to connect to - give that a shot too.
Are you running the PHP on the same server as the MySQL database? I presume so since you used 'localhost'. Can you post the output of 'select user, host, password from mysql.user;'?
I use mysql_connect with a fourth parameter, the database to connect to - give that a shot too.
Last edited by cr-atlanta; 01-22-2013 at 08:59 PM.
Are you running the PHP on the same server as the MySQL database? I presume so since you used 'localhost'. Can you post the output of 'select user, host, password from mysql.user;'?
I use mysql_connect with a fourth parameter, the database to connect to - give that a shot too. <--- Oops, nevermind this, I was thinking of mysqli
But it sounds like you're having connectivity issues locally - have you set the root password?
Last edited by cr-atlanta; 01-22-2013 at 09:01 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.