7

For some reason, Windows 7 is unable to find the MySQL install. I've tried quite a few things to little or no avail.

I want to connect to my MySQL database with php using this code:

$con = new mysqli($server_name,$mysql_user,$mysql_pass,$db_name);
if($con->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
else{
    echo "<h3> Database Connected <h3>";
}

When I do connect, I receive this error message:

Fatal error: Uncaught Error: Class 'mysqli' not found in C:\Apache\htdocs\test_connection.php:8 Stack trace: #0 {main} thrown in C:\Apache\htdocs\test_connection.php on line 8

I ran this code and it returns that I don't have mysqli loaded:

if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
    echo 'We don\'t have mysqli!!! ';
} else {
    echo 'Phew we have it!';
}

I have added

extension_dir = "C:\php\ext"

and

extension=php_mysqli.dll 

to both php.ini-development and php.ini-production

I have my extensions in

C:\php\ext

and I also have the php_mysqli.dll file in that folder.

I have added the following code to the end of my httpd.exe file in Apache

LoadModule php7_module "c:/php/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "c:/php"
15
  • 1
    What have your tried to do in relation to your PHP and Apache setup to resolve this? What does a test page for phpinfo(); report? Commented Jul 16, 2016 at 2:31
  • what does phpinfo say Commented Jul 16, 2016 at 12:49
  • my extension dir is extension_dir = "C:/Apache24/~PHP_download/php-5.6.11-Win32-VC11-x64/ext/" Commented Jul 16, 2016 at 12:50
  • so yours would be = "C:/php/ext/" Commented Jul 16, 2016 at 12:51
  • It takes hours sometimes. Mine took a while due to 32 bit vs 64 bit download discrepancies. total PITA. and the slashes going the "other" way Commented Jul 16, 2016 at 12:52

2 Answers 2

5

For me (on linux debian version) when I migrated from php5 + ubuntu 14 over to php7 + ubuntu 16, it was:

sudo apt-get install php-mysql
Sign up to request clarification or add additional context in comments.

Comments

4

Change

LoadModule php7_module "c:/php/php7apache2_4.dll"

to

LoadModule php7_module /php/php7apache2_4.dll

and

PHPIniDir "c:/php"

to

PHPIniDir /php

I fought this problem for days and the answer was that simple.

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.