8

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"
Drew
  • 24,851
  • 10
  • 43
  • 78
Clynch
  • 81
  • 1
  • 1
  • 3
  • 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? – Drew Jul 16 '16 at 02:31
  • what does phpinfo say – Drew Jul 16 '16 at 12:49
  • my extension dir is `extension_dir = "C:/Apache24/~PHP_download/php-5.6.11-Win32-VC11-x64/ext/"` – Drew Jul 16 '16 at 12:50
  • so yours would be `= "C:/php/ext/"` – Drew Jul 16 '16 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 – Drew Jul 16 '16 at 12:52
  • when you are done, as I said in the first comment, have a php file with `phpinfo();` in a php block. That is it. Google phpinfo() if you need to. When it is all set and healthy after an apache (or whatever) restart, you should have a mysqli block when you scroll down looking at that rendered php file. It should have your flavor of [THIS](http://amishgourd.com/phpinfo7.php) ... scroll down about 40% to see mysqli and or pdo (when you do that beast) – Drew Jul 16 '16 at 12:56
  • @martin I don't know how removing the `mysql` tag benefits this solution right now. It is not like a `sql-server` tag on a mysql question – Drew Jul 16 '16 at 13:30
  • @Drew the tag states: `if the issue related to MySQLi use that tag instead. `, and the MySQLi tag is present, and the code is using MySQLi and PHP7 does not support native MySQL so figured it was more concise to stick with simply the `mysqli` tag. – Martin Jul 16 '16 at 13:33
  • Some of us only filter on say `mysql`. Had it not been mysql to begin with, I would never have found this thing. We don't filter on fringe tags. You are just taking eyes off this thing that could help – Drew Jul 16 '16 at 13:34
  • Also OP specifically states using the `php_mysqli.dll ` extension. Perhaps you should search filter MySQLi as well as MySQL ? – Martin Jul 16 '16 at 13:36
  • I don't care to. I just want the guy to get eyes on his question. Perhaps I should add the PDO tag so maybe someone there can get the guy some help – Drew Jul 16 '16 at 13:39
  • When i run phpinfo(); I do not find a MySQLi block. The only instance of MySQLi in my phpinfo() is under module authors. – Clynch Jul 16 '16 at 14:42
  • The mysql and mysqli block is not present in my phpinfo – Clynch Jul 16 '16 at 14:42
  • Try this link: http://stackoverflow.com/questions/7250356/how-to-install-mysqli – Martin Jul 16 '16 at 18:28
  • I have read the relevant questions already asked including that one, and found no sucess. In the linked question they seem to be doing what i have already done except the mac version. – Clynch Jul 16 '16 at 19:41

2 Answers2

6

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
Priya
  • 1,522
  • 1
  • 14
  • 31
jjX
  • 71
  • 1
  • 4
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.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Frank Hald
  • 41
  • 2