2

I have activated iis7 on my Windows 7 PC.
I have installed php and MySQL too

I am running following php code via localhost to create a D'base namely 'my_files.'

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

$con=mysqli_connect("127.0.0.1", "root", "pass");
// Check connection
    if (mysqli_connect_errno())
  {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

// Create database
$sql="CREATE DATABASE my_files";
if (mysqli_query($con,$sql))
{
 echo "Database my_db created successfully";
  }
else
  {
  echo "Error creating database: " . mysqli_error($con);
  }   ?> 

This Error: "Fatal error: Call to undefined function mysqli_connect() in C:\inetpub\wwwroot\db.php on line 4".

(Other php codes are running fine.) What may be the problem and solution?

BioDeveloper
  • 608
  • 3
  • 7
  • 24

3 Answers3

2

Given your error (undefined function) the mysqli interface is either not enabled in the php.ini file or it can't be loaded for some ready.

Look in your php.ini file for this line:

extension=php_mysqli.dll

make sure it is not commented out. if it was, then un-comment it and restart the web server.

If it is turned on in the php ini then try to figure out why it can't load (check the logs and google, etc).

you can create a trival page:

<?php echo phpinfo(); ?>

and it will show you all of the enabled extensions. after you enable mysqli, open that page and search it for mysqli to find out if it loaded ok.

Don Dickinson
  • 6,140
  • 3
  • 37
  • 30
0

Try with localhost like

$con=mysqli_connect("localhost", "root", "pass");

Otherthan that ..try like to display any error messages while connecting the DB through mysqli

$con = mysqli_connect("myhost","root","pass","database") or die("Error " . mysqli_error($link));

And as @Rens Groenveld said you can go through with the server side configuration error messages from :

error_reporting(E_ALL);
Gautam3164
  • 28,027
  • 10
  • 58
  • 83
  • 1
    Also: Is your server configured to show errors? If you can't find how to do this you can add this at top of your script: error_reporting(E_ALL); It will show PHP errors :) – Rens Groenveld Jul 25 '13 at 12:00
0

Run a phpinfo() to see if the php_mysqli extension module is loaded. If it is not, you should activate mysql extension. For example in php.ini: extension=php_mysqli.dll

Vijay
  • 129
  • 10