5

My question is just similar to this question but I am using PHP version 7.4.1 in Windows 7 [32bit].

<?php
if(!function_exists('mysqli_init') && !extension_loaded('mysqli')){
        echo 'We don\t have mysqli'; 
    }
    else{
        echo'Yes';
    }
    mysqli_connect('localhost', "root", "", "akash");
?>

It returns:

We don\t have mysqli

Fatal error: Uncaught Error: Call to undefinedfunction mysqli_connect()

What I have tried:

As I have seen various answers on this problem and all the answers is simply based on the php.inf file but in my php directory there is no file of this name and so after looking on how to install this I couldn't really find a way, after visiting http://php.net/manual/en/mysqli.installation.php, I scrolled down to find the "PHP 5.3.0 and newer" section where it says I wouldn't need to worry about installing it.

Community
  • 1
  • 1
Akash
  • 425
  • 2
  • 7
  • 21
  • 1
    Run the `phpinfo();` function and display that output to see if mysqli is loaded, or alternatively on the command line do `php -i | grep mysqli`. If it is not, then look in the output of those commands for the path to the php.ini file so you can enable it. – Jeremy Harris Dec 27 '19 at 13:21
  • How do you run the php? Is it called from the command line? Or it runs as a part of some server (e.g. Apache)? – AterLux Dec 27 '19 at 13:26
  • @AterLux using this command in my cmd : php -S localhost:8080 – Akash Dec 27 '19 at 13:28
  • @Jeremy Harris please execuse my ignorance, when i run phpinfo() i got PHP Version 7.4.1 tables but i unable to understand what to do next – Akash Dec 27 '19 at 13:31
  • I meant to write that function in your code (comment that other stuff) and run it. Then in your browser use the "Find" function to search for "mysqli" and also for "php.ini". The latter will show you the full path to the config file. – Jeremy Harris Dec 27 '19 at 13:36

2 Answers2

4

First you need to have a php.ini somewhere.

Usually in the directory with php you have two files php.ini-development and php.ini-production - they are examples of php.ini with some recommended settings.

  1. Copy php.ini-development into php.ini and place it somewhere.

  2. Find the line

;extension=mysqli

and uncomment it (remove the semicolon from the beggining)

  1. Run your server. If php.ini is placed not where php.exe is, then pass the path to it in the command line after -c option:
D:\path\to\php\php.exe -S localhost:8080 -c D:\path\to\ini\file\php.ini ...
AterLux
  • 4,566
  • 2
  • 10
  • 13
  • 1
    sir i already tried this but i am uncommiting ;extension=mysqli and other various types of extension but this not helps me or i forgot to restart my server, but your answer helps me :) – Akash Dec 27 '19 at 13:45
0

If you host the server yourself, in the php.ini file remove the semicolon in front of the extension extension=php_mysqli.dll

BukhariBaBa
  • 171
  • 5