2

I 'm trying to connect to mysql database in my php script. I keep getting the following error:

    Warning: require(mysqli_connect.php): failed to open stream: No such file or directory in C:\xampp\htdocs\simpleIdb\register-page.php on line 52

   Fatal error: require(): Failed opening required 'mysqli_connect.php'   (include_path='.;C:\xampp\php\pear') in C:\xampp\htdocs\simpleIdb\register-page.php on line 52

I 'm running XAMPP 5.5.30 on Windows 10.

Line 52 is: require('mysqli_connect.php');

And the following as mysqli_connect.php:

     DEFINE ('DB_USER', 'horatio');

     DEFINE ('DB_PASSWORD','hmsvictory');

     DEFINE('DB_HOST', 'localhost');

     DEFINE('DB_NAME', 'simpleIdb');

     $dbcon = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)

     OR die ('Could not connect to MySQL:'.mysql_connect_error());

     mysql_set_charset($dbcon, 'utf-8');

My include path in php.ini is:

 include_path=".;C:\xampp\php\pear"

There doesn't seem to be any closure on previous discussions on this issue:

mysqli_connect Fatal Error: require()

Fixing PHP PEAR error

Community
  • 1
  • 1
Fredy
  • 19
  • 4
  • The issue is **where** is your `mysq_connect.php` file? If it's not in the same folder as your php script that is calling `require`, then it will fail to load, and that is what this error is saying. – random_user_name Jan 05 '16 at 23:28
  • cut the mysqli_connect.php page and paste it in the same directory as the script is in. – Atiqur Jan 06 '16 at 06:38
  • My mysqli_connect.php is in the same folder as php script. Also, I tried using absolute path, but that did not work. – Fredy Jan 12 '16 at 22:09

3 Answers3

0

This error means that it cannot locate the 'mysqli_connect.php'

I'd suggest trying to mysqli_connect.php file in the same directory as the file you are attempting to include it in.

Hope this helps!

Derek Pollard
  • 6,953
  • 6
  • 39
  • 59
0

your script is in a different directory than mysqli_connect.php ...

I use an absolute path to mine .. IE include ('/var/www/connect.php');

And .. I use include instead of require, so that if it does fail for some reason .. The error isn't pasting my connect file location, or content (security risk) on the web page.

Zak
  • 6,976
  • 2
  • 26
  • 48
  • At the moment, I 'm not so much concerned about security as I 'm about functionality. See my comment above. – Fredy Jan 12 '16 at 22:13
0

Apparently I don't have enough rep to add a comment on your post yet, so I'm going to try posting an answer.

I'm afraid I don't know much about XAMPP, but I do know quite a but about PHP. Can you output the directory of the current script somewhere? The first thing I would determine is whether or not the mysqli_connect script is in the same folder as the script that's trying to include it. If it's not, you'll have to change your include path, or change one of the script's locations.

TheFrog
  • 56
  • 1
  • 8