Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

php newbie question

Engaged ,
Feb 25, 2010 Feb 25, 2010

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?

TOPICS
Server side applications
343
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 27, 2010 Feb 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";

}

Translate
LEGEND ,
Feb 27, 2010 Feb 27, 2010
LATEST

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";

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines