r/PHPhelp • u/darkNtity • Feb 06 '25
Call to undefined function mysqli_connect()
I've been trying to fix this issue for days, I tried checking if all the configuration files in xampp are set up correctly, I tried uninstalling and reinstalling xampp, nothing seems to work.
I'm bound to using mysqli to connect to a database for my uni project, so I can't look for an alternative.
Does anyone have a solution for this?
0
Upvotes
3
u/allen_jb Feb 06 '25
The mysqli extension isn't enabled. I'm not familiar with xampp and what additional tooling it may provide for making config changes, so these are the manual instructions.
First note that some setups use different configuration files depending on how PHP is run (the SAPI - eg. cli, Apache Module, PHP-FPM). You can check what config files are being used by running
phpinfo()in the same context (eg. as a web request) and looking at the loaded ini files list in the top table.If you don't currently have a
php.inifile, copy either one of thephp.ini-developmentorphp.ini-productionexample files tophp.iniIn your php.ini file, look for a line that looks something like
extension=mysqli. Ensure it does not start with a;(the comment character for ini files)Make sure to restart Apache and/or PHP-FPM after making changes to your configuration. (If you're on Windows you're probably using the Apache module. You can verify this by looking at the "SAPI" value in the output of
phpinfo())If the above doesn't work, check the value of the
extension_dir=setting. In some cases you may need to set this to the full path (egc:\tools\php84\ext\, rather than a relative path)2
u/MateusAzevedo Feb 06 '25
What exactly you did? Are you running the code from CLI or a web request? Remember that's possible to have different php.ini for each case.
What you need to do first: create a PHP file with
phpinfo();in it and access it from your browser. Pay attention on what it says about the .ini files loaded. Verify if that files is loading themysqlextension.Xampp should have everything necessary to connect to MySQL/MariaDB by default (that their whole purpose), but who knows if a previous installation had some left overs causing issue. So the only thing you can do now is confirm that PHP is loading the extension.
Or, if this is giving you too much trouble, maybe try Laragon instead.
1
u/Big-Dragonfly-3700 Feb 06 '25
In the xampp control panel, when you click on the Apache "Config" button, then the "Apache (httpd.conf)" item, what happens? Does a file open or do you get a message about no file, ...?
If a file opens, search in it for the the line - Include "conf/extra/httpd-xampp.conf". This should exist, as it causes the .conf file to be loaded with the the setting in it that php uses to find the php.ini.
In the xampp control panel, when you click on the Apache "Config" button, then the "Apache (httpd-xampp.conf)" item, what happens? Does a file open or do you get a message about no file, ...?
If a file opens, search in it for the the text PHPINIDir. This should exist and the value should be similar to "C:/xampp/php" (including the surrounding quotes). This is the web server setting that php will find that tells it what php.ini to use.
In the xampp control panel, when you click on the Apache "Config" button, then the "PHP (php.ini)" item, what happens? Does a file open or do you get a message about no file, ...?
Also, what operating system and version are you using? Have you directly edited the php.ini (instead of using the "PHP (php.ini)" item in the xampp control panel) and if so what editor did you use? Do you have a .htaccess file present that contains any lines that are overriding any of the above settings that control where and how php gets loaded?
1
u/zolom214 Feb 07 '25
Make sure u correctly installed mysqli ext following this link: https://www.php.net/manual/en/mysqli.installation.php
And then verify that u r running the right php version, which has that extension with xampp