I am getting this Connect Error: 2002 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. I'm trying to make a connection to the DB using this: $db = new mysqli('localhost', 'username', 'password', 'books'); I can log into my DB using the MySQL command line with the root password but for some reason cannot access the database from PHP. Even when I try to access it with the root like this: $db = new mysqli('localhost', 'root', 'rootpassword', 'books'); it still gives the same error. The database 'books' does exist as I can display it from the command line client. Do I have to change something in the php.ini file or some other configuration file because I left the default settings? I'm trying to run this on a Windows Vista machine using IIS 7. Thank you in advance.
I'm doing this on my local Windows Vista machine. I am not using a Web host. I installed PHP and MySQL on my own machine and I got back root password. Do I need to configure something so that PHP can communicate with MySQL properly like assign some special permissions?
But I'm trying to access the database as a root user. Doesn't the root user have access to all databases? When I log in as a root user using the MySQL command line client, I can open all the tables from the database. What permissions are you talking about? When I try to run the php page script, it waits for like 15 seconds and then either shows that error or gives me no output when it should. It seems to be timing out or cannot connect using mysqli to the MySQL database as a root user.
check the mysql configuration, is there any connection time out setup is made and check your php script also
I checked my.ini file and there is nothing set for anything related to timeout. I also checked php.ini and I saw this max_execution_time =300, max_input_time = 60 and mysql.connect_timeout = 60. Are these values normal and what can be the problem? I don't understand why I can log into MySQL using the command line client and cannot connect to it using PHP and the same username and password, ie. root and rootpassword. I also checked and MySQL server and port 3306 that I use for MySQL server are in the allowed list for my firewall so the firewall should not be a problem.
I tried that too. Calling mysql_connect as a procedure and not class. It still does not work. I'm baffled. I followed all of the instructions when installing PHP on Windows and it does not seem to work with MySQL server for some reason. MySQL works on its own through the command line client. Now, I'm not sure if something is wrong with the settings of PHP, or MySQL, or IIS? PHP files do run on IIS without any problems.
Just wanted to post an update. I tried using mysql_connect('localhost','root','rootpassword'); @ mysql_select_db('books') or die("Unable to select database"); instead of $db = new mysqli('localhost', 'root', 'rootpassword', 'books'); and still nothing was fixed. Same thing happens again.
Please check the permissions on /var/lib/mysql . In linux the required permission is 755 so give the corresponding permissions