0

First time user of mysql and php here.

Apache2 is up and running. PHP5 is up and running. MYSQL is up and running; however, when I try to connect to my database I created, i receive a "server error" message with Chromium. With Firefox, there is just a blank page that displays, no error message. The code I've written should spout out an error on the page, but I'm getting a browser "Server error" message instead.

Any ideas?

<?php
$con=mysqli_connect('localhost', 'root', 'pass', 'db1');
if (mysqli_connect_errno($con)){
  echo 'failed to connect: ' . mysqli_connect_error();
}
?>

I'm very confused, because i checked to make sure the mysql server was running, and I double checked my login information as well as database name. I can make changes and create databases from the mysql shell within terminal, but not through PHP!

I'd also add that PHP is working with the Apache server. If i change my code to something like phpinfo(), it works. It's only connecting to mysql that seems to be the problem.

5
  • 1
    Check your server/php error logs, could be a syntax error, could be invalid creds, maybe you don't have mysqli installed, etc. Commented Oct 19, 2013 at 19:22
  • And BTW, the blank page is almost always PHP throwing a fatal error. Commented Oct 19, 2013 at 19:23
  • I installed the php5-mysql package through apt-get as well as mysqlserver, is there anything else i should need? Commented Oct 19, 2013 at 19:33
  • 1
    Look, you haven't even setup your dev environment. You should not be writing code yet. First things first: phptherightway.com/#error_reporting Commented Oct 19, 2013 at 19:37
  • thanks guys...it's up and running now. turning the errors on didn't actually help (but it will in the future while I'm coding!), all I had to do was restart apache...I feel like an idiot. Commented Oct 19, 2013 at 19:51

1 Answer 1

1

Well, In past, before using wamp for my php work, I fell in this issue once, and believe me, it was mysqli extension which wasnt installed..to solve this issue,

turn your errors ON , so that you can see exactly whats going on...see this check your php.ini and make sure that # signed is not present before mysqli extension...see this

I am quite sure that these two steps will resolve your issue

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.