Just starting: loading php.ini

I’m working through Build Your Own Database-Driven Website Using PHP & MySQL, 4th Edition, by Kevin Yank, and have hit problems when connecting to mysql db using the first example php script. I’ve run through the windows installation guide and installed Apache and PHP. I’ve followed the instructions to create the php.ini file in C:\PHP. I’ve added the following to Apache’s httpd.conf:

LoadModule php5_module “C:/PHP/php5apache2_2.dll”
AddType application/x-httpd-php .php PHPIniDir “C:/PHP”

PHP scrips run fine but on trying the first mysql script example I get the following error.

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

Running phpinfo shows the php.ini file isn’t loading, so the mysqli.dll extension isn’t active, giving the fatal error. C:\PHP isn’t shown as a valid path.

I’ve then copied php.ini to C:\WINDOWS, as this is in the path, and restarted apache. The same script runs successfully, but with the following warning:

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

Database connection established. [/FONT]

So, in the immortal words of Marvin Gay, what’s going on? Have the installation instructions missed out on adding C:\PHP to the path, or should updating httpd.conf be enough to pick up the php.ini file?

Is the warning message indicating my installation has a problem?

The book said to come here with any problems, so here I am! Cheers.

pmw’s solution for the:
“Warning: mysqli_connect() [function.mysqli-connect]: Headers and client library minor version mismatch. Headers:50051 Library:50144 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php” problem works for me too. Using xp sp2, php 5.2.13, mysql 5.1.48

I did as PMW (paul) said now i hav no issues with my setup i feel others having the same problem should give a try. Thanks PMW :lol:

Go to the errata for the book.

Find out the Month and Year that your book was printed.

Most likely you will need to copy some dll files across to your windows installation.

I am also languising with the same problem for 3 weeks or so still no respite. My problem is when i try to fetch multiple columns from the databse i get http 500 error(som process is internally getting aborted abnormally i have tried on IIS as well as Apache). This is really making me go crazy.

I’m having the same problem. Its really annoying. I’ve followed the exact steps in the book and keep on getting the warning message. Does anyone know how to get rid of this?

Thanks. The php.ini file already has the extension uncommented - mysql works when it’s present in c:\windows - the query was really to establish if anything was missing from the configuration instructions in the book? From what’s stated in there it seems they expect the change in httpd.conf to be enough to pick up php.ini and therefore complete the configuration.

uncomment (remove ‘;’)
;extension=php_mysqli.dll in php.ini and restart the server


AddType application/x-httpd-php .php PHPIniDir "C:/PHP"

Those should be on two different lines:


AddType application/x-httpd-php .php 
PHPIniDir "C:/PHP"

Try changing that and then restarting the webserver.

Edit>>
Sorry, was too quick in answering…
It seems there is a mismatch between your PHP MySQL extension and your database client software.

You can try lowering error_reporting before calling mysqli_connect() and then increasing it again afterwards.


$err_level = error_reporting(0);
$conn = mysqli_connect('params');
error_reporting($err_level);

It’s not the nicest way of doing this, and it doesn’t actually solve the problem. I think reinstalling MySQL might help, but I’m not sure…

Hi Immerse, that httpd.conf change did the trick with the fatal error, I’m getting connected with a corrected c:\php version and the c:\windows version of php.ini deleted.

I’ll play around with the code you’ve given for suppressing the warning message, but if anyone has chapter and verse on whether the installation is corrupted or if the warning can be ignored I’m still all ears. I’ll carry on for now until I hit problems, or reinstall once I’m familiar with the code and getting annoyed by the warnings. :slight_smile:

Glad it’s fixed!

It’s generally not a good idea to ignore or supress warnings - they’re there for a reason.
I generally tend to stop script execution on even the most trivial notice, that way I know I’m writing error-free code. Sometimes changing the error level can’t be avoided though.

This book has really got me frustrated! I’ve uninstalled/installed MySQL, Apache and PHP and followed the installation guidelines in the book perfectly and can’t get it to work properly. I’ve even tried it on different operating systems and still get the same problem. There must be an error in the installation guidelines, which is an extremely poor mistake by the writer.

The warning message that keeps appearing is having an effect. Whenever I try to extract more than one element from a database table my browser messes up and a ‘send report to windows’ message window appears.

I’m giving up. I’ve tried everything and have wasted 4 days. Definitely returning this book!

I’m having the exact same problem, and I am also using Kevin’s book. I’ve been battling this for several weeks, but it was only in the last couple of days that I learned what the real problem was (PHP not loading php.ini).

I was trying to get Joomla to work. It would not recognize MySQL support. No help from the Joomla forum. They made some suggestions, which didn’t help, because I was already set up correctly (per Kevin’s book).

I tried to install phpMyAdmin. Got “Cannot load mysql extension. Check your PHP configuration.”

Many hours later and some Google searching revealed the real problem was as above: Not loading the php.ini file.

I have still not found the solution. I’ve put the file in the Windows directory (not recommended by most). Same result. PHP is simply not recognizing this file.

There has to be a solution, but at this point, I’m stumped.

I’m running WindowsXP professional with service pack 3 installed, Apache 2.2, PHP 5.2.13 (tried a newer version to see if it would help…didn’t) and MySQL 5.1.

Some information that might help is to investigate the errata for the book.

For example:

p.7 step 2
In PHP 5 or later, you must copy the libmysql.dll file from the PHP installation directory to your system32 directory along with php5ts.dll.

Hi

I ve bought the book and flowed the same instruction but unfortunately i had the same problem…is there any solution…?
thx

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

Warning: mysqli_connect() [function.mysqli-connect]: (/1207959552): in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\welcome\index.php on line 11
Unable to connect to the database

You have an old book. Mine is the 4th edition. The install instructions are written for PHP5.

There is no such note on page 7.

Further, under the Apache configuration instructions, the line is added at the bottom of httpd.conf:

PHPIniDir “c:/php5/”

Hi Billo…

is your post an answer to my question:

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

Warning: mysqli_connect() [function.mysqli-connect]: (/1207959552): in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\welcome\index.php on line 11
Unable to connect to the database

Hi bmcgill, chris_samsung and hussein82, welcome to the forums,

I always have problems with installations. Even though the book recommends installing the components separately so you can later upgrade them separately and you will learn more about how the platform works, don’t let problems stop you from getting on with the book.

IMHO you should try something like XAMPP, WAMP, EasyPHP, etc, that will install all the components in one go. You will be somewhat limited to what versions the components are. But you will not need to worry about dependencies, interoperability, etc.

This book is primarily about learning PHP and MySQL so once you get a platform installed and working you should have no problems with the rest of the book. Then if you want to tackle installing things separately you can always go back and try again later.

Thanks Mittingeague for your reply…

Actually we can use other programmes to run the scrip such as the ones you recommended easyphp, wamp, but the idea behind installing php and mysql separately is to understand how the relationship works between them, the book has recommended that as well so i am trying to flow his methodology to sort the problem step by step and get experience to troubleshoot such problems …

Thanks again

I’m not sure what you are experiencing, but it could be related, I suppose. I was having problems getting php to load the custom php.ini file, and therefore no extensions were being loaded.

Here is what worked. I read this post this morning. Immediately downloaded the new version of php5.3.2, installed it, configured it, started the troublsome programs, and “boom”, they worked. A look at the phpinfo() showed that php was now loading the php.ini file. Link to that SitePoint Forum thread is here: http://www.sitepoint.com/forums/showthread.php?t=664227&goto=newpost