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.

5
  • 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. Commented Dec 27, 2019 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)? Commented Dec 27, 2019 at 13:26
  • @AterLux using this command in my cmd : php -S localhost:8080 Commented Dec 27, 2019 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 Commented Dec 27, 2019 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. Commented Dec 27, 2019 at 13:36

2 Answers 2

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 ...
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.