Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 7 cannot find MySQLi

Tags:

php

mysql

mysqli

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"
like image 686
Clynch Avatar asked Jul 16 '16 01:07

Clynch


2 Answers

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
like image 186
jjX Avatar answered Oct 15 '22 13:10

jjX


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.

like image 45
Frank Hald Avatar answered Oct 15 '22 14:10

Frank Hald