0

So I have a simple PHP script which I attempted to do something along the lines:

$db = mysqli_connect("localhost", "root", "PASSWORD HERE", "database name");
mysqli_query($db, "SELECT STATEMENT HERE") or die (mysqli_error($db));

to try something out. But it won't make a connection to the database. The script is working fine as I tried it on a homeserver and so on, but it won't work on the vps, so I know it's that the mysql server is screwed up.

I'm using Debian 7. I used

apt-get install apache2
apt-get install mysql-server mysql-client
apt-get install php5
apt-get install phpmyadmin

and a bunch of php-* (* = different modules or whatever)

I tried:

mysql -u root -p

and then wrote in the password, and it worked. So what could be wrong?

  • What was the error? – jordanm May 6 '14 at 18:36
  • It doesn't print out any errors. – prk May 6 '14 at 18:37
  • It should in your error log. – jordanm May 6 '14 at 18:39
  • @jordanm I can connect to the server through my webserver. (like, I can connect to the remote MYSQL server through my own homeserver) But not using a php file on the actual VPS. – prk May 6 '14 at 19:19
  • He asked you to look in your error logs for a reason... I'm asking you to do the same... – eyoung100 May 6 '14 at 20:01
0

Do you have the php5-mysql package installed as well? This package (usually) provides the mysql and mysqli php extensions (make sure that you reload the apache configuration when you install new php extensions):

apt-get install php5-mysql

You can check your php configuration to see if you have the mysql / mysqli extensions loaded:

php -m

Or, to check and see if it is enabled in the running apache configuration, create a php file containing a call to phpinfo(); and check to see if mysql is listed in the enabled extensions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.