How do I install MySQL modules within PHP? - 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.

Related

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.

Class 'mysqli' not found PHP v5.6.7

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"

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.

Call to undefined function openssl_random_pseudo_bytes() XAMPP [duplicate]

I spent three hours but I did not find anything; I'm unable to connect to a SSL enabled server. I want to list what i did:
First checked my PHP extensions directory was in order; extension wasn't there, php_openssl.dll
Then I opened my php.ini file but I could not see any extension=php_openssl.dll line to uncomment.
Also, I searched on Google and saw people with the same problem.
http://www.apachefriends.org/f/viewtopic.php?p=162623
However, I also have
OPENSSL_CONF C:/xampp/apache/bin/openssl.cnf
...
openssl
OpenSSL support enabled
OpenSSL Library Version OpenSSL 0.9.8l 5 Nov 2009
OpenSSL Header Version OpenSSL 0.9.8l 5 Nov 2009
no lines . What should I do? Please share your suggestions.
Yes, you must open php.ini and remove the semicolon to:
;extension=php_openssl.dll
If you don't have that line, check that you have the file (In my PC is on D:\xampp\php\ext) and add this to php.ini in the "Dynamic Extensions" section:
extension=php_openssl.dll
[PHP_OPENSSL]
extension=php_openssl.dll
This is the answer.
Things have changed for PHP > 7. This is what i had to do for PHP 7.2.
Step: 1: Uncomment extension=openssl
Step: 2: Uncomment extension_dir = "ext"
Step: 3: Restart xampp.
Done.
Explanation: ( From php.ini )
If you wish to have an extension loaded automatically, use the following syntax:
extension=modulename
Note : The syntax used in previous PHP versions (extension=<ext>.so and extension='php_<ext>.dll) is supported for legacy reasons and may be deprecated in a future PHP major version. So, when it is possible, please move to the new (extension=<ext>) syntax.
Special Note: Be sure to appropriately set the extension_dir directive.
So, what did we do to make openssl_pkey_new() and all the other openssl_ functions in PHP work...
Enabled the extension php_openssl.dll in the (right/active) php.ini. Checked.
Checked that there exists a openssl.cnf in xampp\apache\conf\ (and also in two other directories within XAMPP). Checked.
Added the environment variable OPENSSL_CONF in the Windows system settings with the full path to the above openssl.cnf. Checked.
Restarted Apache (and after that did not work restarted the computer several times...). Checked.
Still does not work, and throwing errors such as
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:02001002:system library:fopen:No such file or directory
error:2006D080:BIO routines:BIO_new_file:no such file
Okay, here are another two more things to check.
1. Trouble with the environment
Run phpinfo() from a PHP script, and go to the "Apache Environment" section. Check the value of OPENSSL_CONF.
Surprise. This is not what we have set in the windows system settings.
The solution is simple. Set the environment variable in the PHP script.
putenv('OPENSSL_CONF=C:\xampp\apache\conf\openssl.cnf');
2. Trouble with relative filenames
Now, openssl_pkey_new() will work, but openssl_pkey_export_to_file() does still not work and returns false without any further explanation?
Check the filename that you have specified as output filename. It will not work in Windows as long as you do not specify the full path.
$folder = realpath('../keyring');
$outfile = $folder.'/private.pem';
openssl_pkey_export_to_file($key, $outfile);
I use xampp. Beforehand I tried the example file "test_smtp_gmail_basic.php" in phpMailer (you can download phpMailer here: https://github.com/Synchro/PHPMailer), but I got the following error:
Mailer Error: The following From address failed: xxx#gmail.com
After I commented out ; extension=php_openssl.dll in php.ini, it is working now.
In xampp, if "extension=php_openssl.dll" is not present in your php.ini file then add it in the "Windows Extensions" section of your php.ini file
and restart your apache.
It works for me..
You will need to edit your php.ini. It's 4 easy steps.
Find your php.ini file.
$inipath = php_ini_loaded_file();
Enable openssl in the file:
extension=php_openssl.dll
Turn allow_url_fopen on
allow_url_fopen = On
Restart apache and you are done!
STEP 1: On your php.ini comment out ;extension=php_openssl.dll
STEP 2: Copy libeay32.dll and ssleay32.dll from your PHP root folder and paste it your Apache/bin folder
STEP 3: Restart Apache
I am assuming that this question is for those using a windows based system.
After making sure that the extension extension=php_openssl.dll in your php.ini file does not have a semicolon.
Then make sure that you have added C:/xampp/apache/bin into your environment path in order to use openssl without having move the command prompt to that directory C:/xampp/apache/bin
Although not related to this question but as the WP migrate Pro docs link to this question I though I would post an answer here.
If your having problems with DB Migrate Pro activating instead of enabling SSL you can just add a line of code to your wp-config
define( 'WPMDB_LICENCE', 'XXXXXXXXXXx' );

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.

Categories