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?

4
  • 2
    add on top: error_reporting(E_ALL); and ini_set('display_errors', true); Commented Jul 25, 2013 at 12:16
  • Try with mssql_connect.. Commented Jul 25, 2013 at 12:27
  • This Error: "Fatal error: Call to undefined function mysqli_connect() in C:\inetpub\wwwroot\db.php on line 4". Commented Jul 25, 2013 at 12:43
  • possible duplicate of Call to undefined function mysql_connect() Commented Jul 25, 2013 at 12:46

3 Answers 3

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.

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

3 Comments

extension=php_mysqli.dll , extension=php_mssqli.dll are activated now. Other php programs running fine. Warning still the same.
yes, but what does phpinfo say? does it tell you the extension is loaded?
one more thing .. if you just changed those, you MUST restart your web server. the extensions are loaded into memory when the web server starts.
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);

1 Comment

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 :)
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

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.