Class 'mysqli' not found PHP v5.6.7 - php

On my Windows 7 machine, with PHP v5.6.7 and MySQL v5.6.23, and using PHPStorm 8, I am attempting to instantiate a mysqli object. When I try, I get:
Fatal error: Class 'mysqli' not found in...
I have also run this test, suggested here:
if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
echo 'no mysqli :(';
} else {
echo 'we gots it';
}
The output is:
no mysqli :(
I read here that this problem is sometimes caused when it looks for the mysqli class within a namespace. I changed my code to correct this, but the issue persists
$mysqli = new \mysqli($host, $userName, $password, $database);
I read that this problem is sometimes caused when the mysqli extension is not enabled. However, I am using PHP version 5.6.7, and the mysqli extension is enabled by default on versions 5.3 and newer (according to here).
Just to be sure, I have verified that php.ini-development and php.ini-production have extension_dir = "C:/PHP/php-5.6.7/ext" and have the semi-colon removed from the lines:
extension=php_mysql.dll
extension=php_mysqli.dll
[Additional information]
I found a test to run and according to phpinfo() it is not loading a configuration file:
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File (none)
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
For some reason, the PHPStorm web server is not looking for php.ini in the right place?
I have this setting in the "Interpreter options" per this:
--php-ini C:\PHP\php-5.6.7\php.ini
I have verified that this is the correct path.

scrowler and Michael Bush pointed out the answer in comments above. I thought I'd create an answer for it for the benefit of someone viewing the thread. Thanks, scrowler and Michael Bush.
The php.ini-development and php.ini-production files are templates. In order to have effect, one of them needs to be copied and renamed php.ini.

Have you added the PHP installation directory to you environment path
right click on my computer from the start menu
click on properties
find advanced system settings
click on environment variables
under system variables find PATH add C:\php replacing C:\php with your PHP
installation directory; *** remember the path separator
Also check this entry in your php.ini
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "c:/php/ext"

Related

Call to undefined function mysqli_connect on PHP for windows

I have the following code:
<?php
DEFINE ('DB_USER', 'test');
DEFINE ('DB_PASSWORD', 'test');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'site');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('Could not connect to MYSQL ' . mysqli_connect_error());
?>
If I run this I will get this error message:
Fatal error: Uncaught Error: Call to undefined function mysqli_connect()
I'm using PHP for Windows downloaded
From what I have read, you're supposed to uncomment parts in your php.ini file. There is no php.ini in my PHP folder, but only php.ini-development and php.ini-production.
I've tried renaming one of the files to php.ini and uncommenting extension=mysqli, but the problem is still there.
How can I solve this issue?
I was having this same issue, and most stackoverflow answers didn't really clearly address this other step you need to take in setting up your php.ini. If you just uncomment extension=mysqli php still has no idea where any of your extensions are actually located, so it will fail to load them. Locate the section of your php.ini that looks something like:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"
And then uncomment the bottom "extension_dir" value and fill in the value with the absolute path of your "ext" directory, ie:
extension_dir = "<absolute-path-to-ext-folder>"
Once I completed these two steps (uncommenting extension=mysqli and then adding the absolute path in extension_dir), mysqli loaded correctly
There are two files php.ini-development and php.ini-production
There is no php.ini file in the php directory
so you have to create one
Step1: Copy the php.ini-development into new file named php.ini
Step2: Uncomment ;extension=mysqli by removing ; from the starting of line no: 928
Step3: Replace the ext with exact location of ext folder of php in line no:763 extension_dir = "ext" Ex: extension_dir = "C:/Program Files/php/ext" and save the file
Step4: php -m run in terminal and look for mysqli, it its there then everything is working fine
As the setup say you have to rename one of those 2 you have, if you don't PHP will go with defaults.
So change one of them to php.ini and uncomment the line - this should not really be needed as far as i recall.
For Windows, you can find the file in the C:\xampp\php\php.ini-Folder (Windows) or in the etc-Folder (within the xampp-Folder).
Under Linux, most distributions put lampp under /opt/lampp, so the file can be found under /opt/lampp/etc/php.ini.
If you can't find it. Then you should rename one of those to php.ini file.

How to install mysqli (Fatal error: Class 'mysqli' not found) NO mysqli section in phpinfo() [duplicate]

I just deployed my website to a staging environment and am getting the following error:
Fatal error: Class 'mysqli' not found in D:\ClientSites\baileyboiler.com\www\new\php\db.php on line 11
At first I assumed that MySQLI was simply not installed, but running a phpinfo() reveals the following:
To me it looks like MySQLI is installed (though I could be reading this wrong). What should I do?
Code
class DB
{
public static function GetConnection()
{
return new mysqli(DBHOST, DBUSER, DBPASSWORD, DEFAULTDATABASE);
}
}
(line 11 is the return new mysql(...);)
Update
I added extension=php_mysqli.dll to my php.ini located at /Windows/php.ini (according to phpinfo(), this is the one being loaded):
Loaded Configuration File C:\WINDOWS\php.ini
But the error persists. I know that mysqli.dll exists at C:\php\ext - because I can see the file. What now?
I got the error corrected by enabling/editing the following config in php.ini:
1st (uncomment and add config):
include_path = "C:\php\includes"
2nd (uncomment):
extension_dir = "ext"
3rd (uncomment and edit config):
extension=D:/PHP/ext/php_mysql.dll
extension=D:/PHP/ext/php_mysqli.dll
Make sure is enabled under php.ini just find php_mysqli.dll and remove semi-colon and restart apache
Christian Mark is right but I think it need:
4rd Copy php.ini to "C:\Windows". On my computer, need copy it to "C:\Windows", Because phpinfo() output "Configuration File (php.ini) Path: C:\Windows" and "Loaded Configuration File: C:\Windows\php.ini"
5rd login out Computer and login in.
Then it work for me.
If I don't do 4,5rd, It's also don't work for me, the phpinfo output include_path is not my configured. and extension_di also not. run the test also not work.

PHP: Fatal error: Class 'SoapClient' not found

First of all, I've read this question (Fatal error: Class 'SoapClient' not found) and have everything done the answer says. But still experience an issue.
I also found similar issue here (https://bugs.php.net/bug.php?id=64445) but it is not solved there too.
I'm trying to set up a PHP + Apache environment on Win 7 64.
PHP: php-5.5.17-Win32-VC11-x86. Thread safe.
Apache: httpd-2.4.10-win32-VC11
So, here is my C:\PHP\php.ini for SOAP. Everything is set correctly:
extension=php_soap.dll
; Directory in which the loadable extensions (modules) reside.
; On windows:
extension_dir = "C:/PHP/ext"
[soap]
; Enables or disables WSDL caching feature.
; http://php.net/soap.wsdl-cache-enabled
soap.wsdl_cache_enabled=1
; Sets the directory name where SOAP extension will put cache files.
; http://php.net/soap.wsdl-cache-dir
soap.wsdl_cache_dir="/tmp"
; (time to live) Sets the number of second while cached file will be used
; instead of original one.
; http://php.net/soap.wsdl-cache-ttl
soap.wsdl_cache_ttl=86400
; Sets the size of the cache limit. (Max. number of WSDL files to cache)
soap.wsdl_cache_limit = 5
In C:/PHP/ext folder I have php_soap.dll file, C:\PHP\ext\php_soap.dll.
But my phpinfo(); returns ONLY this about SOAP:
I DO NOT have these settings shown:
And I get error:
Fatal error: Class 'SoapClient' not found in C:\Apache24\htdocs\myApp\src\Em\Bundle\PlatformBundle\Services\MyAppService.php on line 46
What did I miss? How to solve it?
This is very easy.
You work with Symfony2 i think and you use namespaces. This function is in the Root-Namespace.
use:
\SoapClient()
Otherwise you are in the namespace and they can't find the class.
You have the same Problem with the Exception class for example.
If you are on linux and you are missing the soap extension, like I was and you have already enabled it in php.ini then try
apt-get install php-soap
service apache2 restart
I had the same issue in a custom module Drupal 8.
It uses Symfony2 so just add this in controller :
use SoapClient;
in PHP/7.4.11 Server
In XAMPP Control Panel
Stop Apache Server
Click on Config next to Apache
From dropdown select PHP (php.ini)
Ctrl+F to find ;extension=soap and remove ; from the line.
Ctrl+S to save the file.
Start Apache again.
this steps solved my problem.
Try config the extension using the path:
extension=ext/php_soap.dll
In phpinfo() you can see this important lines:
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\Apache24\bin\php.ini
But you can change the ini folder if desire in httpd.conf:
# configure the path to php.ini
#PHPIniDir "C:/php"
BUT SEE what extension dir are you using:
extension_dir C:\php
In the "Core" section. This can be configured too.

MySQLi not found error

I just deployed my website to a staging environment and am getting the following error:
Fatal error: Class 'mysqli' not found in D:\ClientSites\baileyboiler.com\www\new\php\db.php on line 11
At first I assumed that MySQLI was simply not installed, but running a phpinfo() reveals the following:
To me it looks like MySQLI is installed (though I could be reading this wrong). What should I do?
Code
class DB
{
public static function GetConnection()
{
return new mysqli(DBHOST, DBUSER, DBPASSWORD, DEFAULTDATABASE);
}
}
(line 11 is the return new mysql(...);)
Update
I added extension=php_mysqli.dll to my php.ini located at /Windows/php.ini (according to phpinfo(), this is the one being loaded):
Loaded Configuration File C:\WINDOWS\php.ini
But the error persists. I know that mysqli.dll exists at C:\php\ext - because I can see the file. What now?
I got the error corrected by enabling/editing the following config in php.ini:
1st (uncomment and add config):
include_path = "C:\php\includes"
2nd (uncomment):
extension_dir = "ext"
3rd (uncomment and edit config):
extension=D:/PHP/ext/php_mysql.dll
extension=D:/PHP/ext/php_mysqli.dll
Make sure is enabled under php.ini just find php_mysqli.dll and remove semi-colon and restart apache
Christian Mark is right but I think it need:
4rd Copy php.ini to "C:\Windows". On my computer, need copy it to "C:\Windows", Because phpinfo() output "Configuration File (php.ini) Path: C:\Windows" and "Loaded Configuration File: C:\Windows\php.ini"
5rd login out Computer and login in.
Then it work for me.
If I don't do 4,5rd, It's also don't work for me, the phpinfo output include_path is not my configured. and extension_di also not. run the test also not work.

How do I install MySQL modules within PHP?

I've updated php.ini and moved php_mysql.dll as explained in steps 6 and 8 here.
I get this error…
Fatal error: Call to undefined function mysql_connect() in C:\inetpub...
MySQL doesn't show up in my phpinfo; report.
I've updated the c:\Windows\php.ini file from
; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"
to
; Directory in which the loadable extensions (modules) reside.
extension_dir = ".;c:\Windows\System32"
Result: no change.
I changed the php.ini value of extension_dir thusly:
extension_dir = "C:\Windows\System32"
Result: much more in the phpinfo; report, but MySQL still isn't working.
I copied the file libmysql.dll from folder C:\php to folders C:\Windows\System32 and C:\Windows
Result: no change.
I stopped and restarted IIS.
Result: new, different errors instead!
Warning: mysql_connect() [function.mysql-connect]: Access denied for
user '...'#'localhost' (using password: YES) in C:\inetpub\...
error in query.
Fatal error: Call to a member function RecordCount() on a non-object
in C:\inetpub\...
I found several .php files in the website where I had to set variables:
$db_user
$db_pass
Result: The site works!
As the others say these two values in php.ini are crucial.
I have the following in my php.ini: note the trailing slash - not sure if it is needed - but it does work.
extension_dir = "H:\apps\php\ext\"
extension=php_mysql.dll
Also it is worth ensuring that you only have one copy of php.ini on your machine - I've had problems with this where I've been editting a php.ini file which php isn't using and getting very frustrated until I realised.
Also if php is running as a module within apache you will need to restart the apache server to pickup the changes. Wise to do this in anycase if you're not sure.
a "php -m" from the cmd prompt will show you the modules that are loaded from the ini file.
In the php.ini file, check if the extention path configuration is valid.
You will need to enable the extension=php_mysql.dll option in the php.ini as well. Also, make sure that the file is in the extension_dir you set.
You can read more about it at:
http://us3.php.net/manual/en/install.windows.extensions.php
On a completely different note, might I suggest WampServer? It should get you up and running with a Apache/PHP/MySQL install in no time.
You could even compare the WampServer config files with your own to see where you originally went wrong.

Categories