Skip to main content
Inspiring
February 25, 2010
Answered

php newbie question

  • February 25, 2010
  • 1 reply
  • 331 views

Normally I work with C# but now I'm playing around with PHP and it's fun. So I type code from books over and try to make some small things of my own.

I've got this piece of code:

$mysqli = new mysqli( 'localhost','root','wrongpassword','sportjegeestgezondblog');
    if ($mysqli->errno) echo "unable to connect to database"; else echo "connected";

Where I deliberately give the wrong password but still mysqli->errno keeps returning 0 what am I doing wrong?

This topic has been closed for replies.
Correct answer David_Powers

If you are using > PHP 5.2.9 or > PHP 5.3.0:

if ($mysqli->connect_error) {

  echo "unable to connect to database";

} else {

  echo "connected";

}

1 reply

David_Powers
David_PowersCorrect answer
Inspiring
February 27, 2010

If you are using > PHP 5.2.9 or > PHP 5.3.0:

if ($mysqli->connect_error) {

  echo "unable to connect to database";

} else {

  echo "connected";

}