Problem connecting to mySQL

I’m working my way through ‘Build your own database driven website’ and I’m currently up to chapter 4, which is using php to connect to a mqsql database. I’ve used the code example in the book and when I try to view the page in my browser it says the following:

Warning: mysqli_connect() [function.mysqli-connect]: Headers and client library minor version mismatch. Headers:50051 Library:50145 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

I suspect this is not to do with the code itself but is a configuration issue…has anybody got any ideas on how to fix it? I can’t really go any further until I’ve got this right and if it is a config issue nothing will work anyway until it’s corrected.


What versions of PHP and MySQL are you using?

PHP 5.2.13 and MySQL 5.1 - basically, the latest versions that were available last week when I installed.

I’m having the same issue as pollythena. I also have PHP 5.2.13 and MySQL 5.1. Thus far I have been unable to find a resolution on the internet and I’m hoping that someone here has a fix. Thanks.

First fix suggestion is always going to be ‘update’…just like any video card manufacturer says… update your drivers.
PHP Current Version: 5.3.2
MySQL Current Version: 5.1.45

Okay, I’m now running the latest version of PHP (5.3.2) and was always running the most up to date version of my SQL.

The error message has changed!

It now says:

Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

Now this means there must be something wrong with the first part of the code but I don’t for the life of me know what it is. I’ve copied it exactly from the book (I’m handtyping it because I tend to learn more that way than copy and pasting) and I’ve just gone through it character for character and it’s correct.

This is the first part of the code, the first line is line 2 of the php file and comes straight after the <?php bit:

$link = mysqli_connect(‘localhost’, ‘root’, ‘password’);
if (!$link)
$output = ‘Unable to connect to the database server.’;
include ‘output.html.php’;

I’ve obviously put my password in where I’m supposed to.

Any ideas?

When you updated PHP, you installed it without mysqli.

I am going round and round in circles…

When I installed the newest version of PHP I altered the php.ini with the following details:

doc_root = (file path to htdocs)

extension_dir = “C:\PHP\ext”

Then I looked for this:


and removed the semicolon from in front of it. And yes, it’s definitely mysqli not just mysql.dll.


session.save_path = “C:\Windows\Temp”

I’m still getting the same error message about undefined function. If it’s because mysqli isn’t installed, what exactly do I need to do to get it installed?

Is php_mysqli.dll in \php\extensions ?

Does the php.ini extension_dor setting point to that folder?

Yes to the first, and this is the relevant section from the php.ini file:

; Directory in which the loadable extensions (modules) reside.
; extension_dir = “C:\PHP\ext”
; On windows:
; extension_dir = “C:\PHP\ext”

You need to uncomment one of those extension_dir lines, and ensure that the path it’s pointing to is correct.

Oh my God it works! does happy dance

Thanks to everyone who helped, even if it some of it was probably quite straightforward. Hopefully I won’t be back…