Fatal error: Call to undefined function mysqli_connect() in C:\\Program Files (x86)\\Ap

I know there’s another thread on this but it doesn’t help me.

Reading Database Driven Websites and I come to this error when I try to run this code:

<?php
$link = mysqli_connect('localhost', 'root', 'password');
if (!$link)
{
    $output = 'Unable to connect to the datbase server.';
    include 'output.html.php';
    exit();
}

if (!mysqli_set_charset($link, 'utf8'))
{
    $output = 'Unable to set database connection encoding.';
    include 'output.html.php';
    exit();
}

if (!mysqli_select_db($link, 'ijdb'))
{
    $output = 'Unable to locate the joke database.';
    include 'output.html.php';
    exit();
}

$output = 'Database connection established.';
include 'output.html.php';?>

Of course, I filled in password with my real password. I checked my PHP info and the Loaded Configuration File was configured correctly i.e. extension=php_mysqli.dll was uncommented in php.ini. My php version is 5.3.5. I installed the thread safe version of PHP. I tried changing the localhost to 127.0.0.1. I tried everything in that thread and nothing helps. I can’t even get a different error message. It just keeps coming up: Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2.

Can someone please help. I’m itching to move on in the book. Thanks in advance.

Run the following:

<?php
echo 'The following PHP extensions are loaded on this server';
echo '<pre>';
print_r(get_loaded_extensions());
echo '</pre>';
?>

It will list all the PHP extensions which are currently loaded on the server concerned. Is there an entry in the outputted list for mysqli ?

This is what I get:

The following PHP extensions are loaded on this server

Array
(
[0] => Core
[1] => bcmath
[2] => calendar
[3] => com_dotnet
[4] => ctype
[5] => date
[6] => ereg
[7] => filter
[8] => ftp
[9] => hash
[10] => iconv
[11] => json
[12] => mcrypt
[13] => SPL
[14] => odbc
[15] => pcre
[16] => Reflection
[17] => session
[18] => standard
[19] => mysqlnd
[20] => tokenizer
[21] => zip
[22] => zlib
[23] => libxml
[24] => dom
[25] => PDO
[26] => Phar
[27] => SimpleXML
[28] => wddx
[29] => xml
[30] => xmlreader
[31] => xmlwriter
[32] => apache2handler
[33] => mhash
)

I’m jealous. My hosting company doesn’t have mcrypt. LOL

Can someone please help me with this? I’ve been all over the internet looking for a solution and I literally can’t find anything that helps.

Did you remove the ; from in front of the extension=php_mysqli.dll or was it not there, if you removed it, did you reboot the server afterwards?

Removed it a restarted the server.

Ok. I figured out the original problem but now I get these error messages:

Warning: mysqli_connect() [function.mysqli-connect]: [2002] No connection could be made because the target machine actively (trying to connect via tcp://127.0.0.1:3306) in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): No connection could be made because the target machine actively refused it. in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

Any suggestions for these new problems? Thanks.

Check your firewall, it may be blocking access to the port

Turned off all firewalls and still getting the same messages.

Try going back to using localhost for the hostname

Yeah, tried that too. The error message just changes from: (trying to connect via tcp://127.0.0.3:3306)

to: (trying to connect via tcp://localhost:3306)

Wow. I’ve been at this for hours and I just can’t find a solution. Very frustrating.

Verify the mysql server is running and boud to a network port as opposed to trying to use a socket.

Apache is running on port 80.

You said you have figured out the original problem. I am experiencing the exact same problem, would you care to share with me the solution?

If you’re getting the error message:

Fatal error: Call to undefined function mysqli_connect()

then, the “mysqli” module is probably not being loaded by php. You can confirm this by running phpinfo(); in your php code. If “mysqli” is not listed in the resulting page, then it is not being loaded.

I’m using php 5.3.6, and mysql 14.14 on Windows 7. The solution that successfully loads “mysqli” for me (and prevents the above error message) is to download “libmysql.dll” from libmysql.dll free download - DLL-files.com and put it in my path, or just copy it to my Windows folder.

Ironically, I found this solution by reading PHP: Installation - Manual, which says that for php 5.3.0+ you don’t need to configure access to “libmysql.dll”!