Uncaught PDOException: could not find driver even when the extensions are there - php

Another one for this error that is driving me nuts.
I've read literally 50 posts in stackoverflow and tried all different solutions:
Checking php.ini to see if the extensions are enabled and the folder to check if the dll's are present
Also tried extracting a php_pdo_mysql.dll file from the latest php version, checking if maybe the xampp original file was broken or corrupted with no luck.
Setting the path in environment variables
This is what I'm using for my local environment:
Xampp 7.2.4
PHP 7.2.4
Apache 2.4.33
And this is my code:
return new PDO('
mysql:host='.Env::getInstance()->env('dbhost').';
dbname='.Env::getInstance()->env('dbname'),
Env::getInstance()->env('dbusername'),
Env::getInstance()->env('dbpassword')
);
Is there something I haven't tried? please I want to fix this issue for once and for all.
Thanks in advance.

The arguments passed to the PDO constructor must be like $dsn in the example of the php manual below.
<?php
/* Connect to a MySQL database using driver invocation */
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}
?>
It looks like your first argument has the wrong content.

Related

Error connecting to SQL Anywhere 16 with php 7.1.7 (dbcapi.dll not found)

I run a IIS Webserver with php 7.1.7 and the propriate SQL Anywhere extension.
Anywhere Client is installed in 32bit and 64bit version.
When connecting to database with
$conn = sasql_connect("UID=***;PWD=***;ENG=MyEng;LINKS=tcpip{host=192.168.2.204;port=2638}");
I receive as error:
The SQLAnywhere client libraries could not be loaded. Please ensure
that dbcapi.dll can be found in your PATH environment variable.
But all seems to be fine:
dbcapi.dll is in c:\Program Files\SQL Anywhere16\BIN32 and ...\BIN64
both paths are included in PATH variable and also shown in phpinfo
SQL Anywhere is shown in phpinfo output as well
What else can I check?
Regards
Florian
actually I don't know really why, as all settings, variables, taskes are same, but after a server reboot, now message is gone and it works.
Florian

PHP Warning: PHP Startup: Unable to load dynamic library '- The specified procedure could not be found. in Unknown on line 0

I would like to change php version to 7.1 and i have an error:
PHP Warning: PHP Startup: Unable to load dynamic library
'C:\Program Files\PHP\v7.1\ext\php_sqlsrv_7_nts_x86.dll' - The specified procedure could not be found.
in Unknown on line 0
First think. This is not duplicate question because i checked many similar questions.
I'm using IIS, PHP 7.1, and SQL server (thats why i need sqlsrv drivers).
I checked php.ini file aready and i change extension-dir path to full path but nothing happens. (Logically if path is a problem why it works with other extensions? ).
It works with PHP 7.0.7 (all enabled extensions is exactly same)
Update: still won't work but i tried to paste path from error message to file explorer and file already there.
Turns out that PHP 7.0 and PHP 7.1 are not compatible and the mssql PDO drivers are for 7.0.
Github issue here
Also ensure you including the right 64/86 and ts/nts version.
As from Toby Allen's accepted answer above 7.0 and 7.1 are incompatible,
However Microsoft has released Preview versions of the drivers for 7.1.
This worked for me, hope it helps anyone searching.
Drivers can be found here under downloads
I had this issue yesterday. The key to the error is the last bit.
The specified procedure could not be found.
In my case I went through a painful amount of debugging. The first thing that I noticed was that when I ran a hello world php file, I didn't get this error. That indicated to me it wasn't actually a problem loading the file, it was a problem calling a function in the file.
I went in and repeatedly put die() statements in and moved it until it hit the error. It took awhile but I eventually discovered I was calling sqlsrv_connect with options that were (apparently) now invalid.
So I can't say the exact cause of your issue without seeing the code that actually causes the error, but I hope this at least points you in the right direction.

"The specified procedure could not be found" IIS 6.0 and PHP5

I am trying to make PHP5 work over IIS 6.0 on Windows server 2003 and i am following this steps:
http://www.iisadmin.co.uk/?p=4
The thing is, there's no file named "php5isapi.dll" inside the php folder, so I am using php5isapi.dll instead. Is it correct? Or should I try to download the php5isapi.dll from somewhere.
Well, then, I keep following the steps and when I try to execute my php file, I get this message:
The specified procedure could not be found.
What am I doing wrong?
Thanks.
UPDATE
I downloaded php5isapi.dll and tried to make it work with it but i am getting this error:
The specified module could not be found.
Also, after any change, i restart the Default Web Site clicking on stop and play.
UPDATE 2
Now, after rebooting, when trying to access the PHP file, the browser shows a 500 error:
The page cannot be displayed
I noticed that "php5isapi.ll" is no longer available for the last versions of PHP as pointed in here:
Why is php5isapi.dll missing after installing PHP for Windows?
Therefor, what i did was following this tutorial in order to do it with FastCGI
http://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/using-fastcgi-to-host-php-applications-on-iis-60
I found it on this comment:
Why is php5isapi.dll missing after installing PHP for Windows?
After restarting the server, it finally worked.

Zend FR finfo error Warning: string extension `B' invalid

I have problems after updating Zend FR to 1.11
Mimetype file checking generates:
Warning: string extension `B' invalid
It looks like cause of problems the string in the Zend_Validate_File_MimeType
$finfo = finfo_open(FILEINFO_MIME_TYPE, $file);
I have created simple test case
$finfo = finfo_open(FILEINFO_MIME_TYPE, '/usr/share/misc/magic');
echo finfo_file($finfo, PUBLIC_HTML_PATH . '/images/missing.png');
finfo_close($finfo);
And i got same error :(
finfo_open(FILEINFO_MIME_TYPE, '/usr/share/misc/magic'); //generates: Warning: string extension `B' invalid.
My OS: Kbuntu 10.10
Where am i wrong?
Ran into the same error message ("Warning: string extension w' invalid in Command") as Mike Purcell, but the fix for it was different.
On our servers we had a /usr/share/misc/magic and a /usr/share/misc/magic.mgc file. The magic.mgc file had been compiled from the magic file, but PHP still wasn't happy talking directly to the /usr/share/misc/magic file (we'd shifted to that file as part of debugging that the magic.mgc file needed updating).
The fix for us was changing our putenv line back to the magic.mgc file:
putenv('MAGIC=/usr/share/misc/magic.mgc');
Then, magic-ally :-) , the whole mime-type detection system started working again.
This may not pertain to your EXACT issue, but it did resolve the issue I was having which resulted in a very similar error message: "Warning: string extension w' invalid in Command".
For us, we have a heterogenous setup where some servers are still running php 5.2 and others running php 5.3. On the 5.2 boxes the magic file resides in /usr/share/file/magic, but on the 5.3 boxes the file resides in the default path of /usr/share/misc/magic. Apparently someone tried to reconcile these path differences by symlinking the 5.2 path so the codebase could be php version agnostic. But according to some comments posted on PHP site regarding symlinks to the magic file, it will result in unexpected behavior, which of course was resulting in the aforementioned error message.
So be sure the path you are passing is to the actual magic file, and not a symlink, and see if that resolves your issue.
Depending on your PHP version the magic format may be updated. This is documented in a note at http://php.net/manual/en/function.finfo-open.php
run php -v to see your version
I got the same error when pointing to an older magic file in our source tree, and resolved it when pointing to a newer magic file from my current linux distro
I had this error in Laravel (minus Zend FR, of course). Running PHP 5.3.21 on a Windows box with IIS.
Finding very little info online I was close to giving up. It worked initially when I followed instructions in the comments on PHP.net, which were basically to add fileinfo.dll to your PHP installation, and to also download the relevant magic files and point an environment variable to them.
There was some initial confusion until I realised I didn't actually have php_fileinfo.dll, so as well as adding it to the php.ini file, I had to download the file itself and add it to my ext directory.
Now what really had me stuck, was that it worked initially. The next day it didn't. To cut a long story short, it didn't need the environment variable, MAGIC. The reason this had me stuck, is because I had tried every possible scenario, but once the environment variable had been set, it had been set. And I had to restart the Windows server after removing it, to unset it. Once I did this it worked perfectly.

wamp cannot load mysqli extension

WAMP installed fine, no problems, BUT...
When going to phpMyAdmin, I get the error from phpMyAdmin as follows:
Cannot load mysqli extension. Please check your PHP configuration
Also, phpMyAdmin documentation explains this error message as follows:
To connect to a MySQL server, PHP needs a set of MySQL functions
called "MySQL extension". This extension may be part of the PHP
distribution (compiled-in), otherwise it needs to be loaded
dynamically. Its name is probably mysql.so or php_mysql.dll.
phpMyAdmin tried to load the extension but failed. Usually, the
problem is solved by installing a software package called "PHP-MySQL"
or something similar.
Finally, the apache_error.log file has the following PHP warnings (see the mySQL warning):
PHP Warning: Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0
PHP Warning: Zend Platform does not support this version of PHP - please upgrade to the latest version of Zend Platform in Unknown on line 0
PHP Warning: Zend Debug Server does not support this version of PHP - please upgrade to the latest version of Zend Debug Server in Unknown on line 0
PHP Warning: gd wrapper does not support this version of PHP - please upgrade to the latest version of gd wrapper in Unknown on line 0
PHP Warning: java wrapper does not support this version of PHP - please upgrade to the latest version of java wrapper in Unknown on line 0
PHP Warning: mysql wrapper does not support this version of PHP - please upgrade to the latest version of mysql wrapper in Unknown on line 0
So, for some reason PHP is not recognizing the mysql extension.
Anyone know why? Any solution or workaround?
I deleted the PHP in program files ad everything started working , the problem that there two installations of pHp
I tried many solutions, and none worked for me. I tried the following solutions:
Restart wampserver
Reinstall wampserver
restart machine
and all other solutions mentioned in this question.
However, none of these worked. Then I found that my PHPMyAdmin was not working in chrome and was working in firefox. So I tried clearing cache, restarting browser etc, but still it would not work.
Then I deleted all the files from C:\wamp\tmp and then tried again, and it works. I am not sure why it works, but here is what I think. The session was cached and not getting cleared. So as soon as I deleted all files in this directory all the sessions were deleted and hence it worked fine.
First, make sure that the php.ini file is loading the mysqli extension.
If you are using WAMPServer, click on the icon in the system tray, go to PHP -> PHP Extensions and make sure it is checked. If not, go into the php.ini file and make sure that the line: extension=php_mysqli.dll is uncommented (eg, remove the ; if it exists). If that line does not exist, add it.
If this still does not work, double check that the right php.ini file is being loaded.
To do so, view your phpinfo() (Here for WAMPServer). Scroll down to the Loaded Configuration File row and see which php.ini is being loaded.Make sure it is the right file. If you're using WAMPServer, it should be(WAMP INSTALL FOLDER)\bin\apache\Apache2.2.11\bin\php.ini. By default, it isC:\wamp\bin\apache\Apache2.2.11\bin\php.ini`.
If a different php.ini file is being loaded, just rename it to something else so that PHP will try and find the file somewhere else. There should be a way to specify which on eyou want to use, but I forget exactly how to do that...
If this still doesn't work... Try messing around with phpMyAdmin's settings, or using another answer, but I'm afraid I can't help beyond this.
I was running WAMP with two PHP versions 1) 5.2.9 and 2) 5.2.13.
As per site requirement i needed to change PHP version to 5.2.9 from 5.2.13. after swapping PHP version, error was "mysqli extension is missing". after debugging long time i get to know it was due to wrong "extension_dir" path in php.ini file.
So i changed its value:
Old: "extension_dir" c:/wamp/bin/php/php5.2.13/ext/
New: "extension_dir" c:/wamp/bin/php/php5.2.9/ext/
Restarted All services in wamp server, then it's fixed.
I had the same problem. I had WAMP server installed. All was working fine. Then one day I restarted my computer and it just stopped working! I tried desperately going through all help posts and doing them but nothing worked.
What they usually suggest you do is, first go to your php.ini file and make sure your 'extension_dir' is properly set. Then to make sure these two lines are not commented (remove the ; infront):
extension=php_mysql.dll
extension=php_mysqli.dll
Then some suggested that I download fresh copies of these two files but none worked. I also tried uninstalling everything (php/mysql/apache) and reinstalled fresh copies of WAMP server several times but with no luck.
Finally I managed to find an alternative solution. I switched to 'easyphp' (http://www.easyphp.org/). This is something very similar to WAMP. First I made backups of my sql databases so I can reload them on the new installation.
Then I installed 'easyphp' and everything seems to work fine. I reloaded my sql databases from my backup and now things are back to normal.
I hope someone suffering from a similar prob. will find this useful. If someone has really found a fix to make WAMP server work. Pls do be kind enough to post it here so many will benefit.
in wampserver go to php.ini. open the file and uncomment extension=msql.dll by removing semicolon(;) for respective operating sytem.
Just add in your php.ini:
[PHP_MCRYPT]
extension=php_mcrypt.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
Also setup the mysql password:
SET PASSWORD FOR root#localhost=PASSWORD('your_password');
And the phpmyadmin mysql password in config.inc.php:
$cfg['Servers'][$i]['password'] = 'your_password';
Had the same problem, with wamp. Try to exchange your current version of php.ini with a backup. There is one in: wamp\bin\php\php5.3.0phpForApache.txt. Worked for me.
Just wanted to chime in on this one. Using Wamp Server 2.0, and using Zend Studio with Zend debugger for development.
I wasn't able as of yet (will get back to it at some point) to get the zend debugger working with php 5.3. So in wamp I loaded an earlier php version, 5.2.11. I was getting the same error when acessing php my admin.
What I had to do was change the php.ini file value for "extension_dir" to c:/wamp/bin/php/php5.2.11/ext/ to match the version of php I was using. After that it was all good.
I had this problem and spent 2 hours trying all the solutions online, none worked.
Tried this, and it woked:
Change
mysql.default_host =
to
mysql.default_host = localhost
and restart WAMP. pay attention if you are using mysqli or not.
I had the same error. When I increased the script memory size and enabled E_ALL then restarted the server, I got that error in phpmyadmin. All I had to do to fix it was restart my computer!
I got this problem for a long time. Tried all I've read on forums and this finally worked for me:
Open your php.ini (I assume you've got the good one that is loaded...) and find this line
mysqli.default_port = 3306
change for
mysqli.default_port = 80
Restart all services
Go to localhost/phpmyadmin -> won't work
Reopen the php.ini file and retype this
mysqli.default_port = 3306
Restart all services
Worked for me.
For me worked this, after searching all logs/internet/every non-normal things.
You have to register dl by:
Through application:
WAMP -> PHP settings -> enable dl
or
# php.ini #
; Whether or not to enable the dl() function. The dl() function does NOT work
; properly in multithreaded servers, such as IIS or Zeus, and is automatically
; disabled on them.
; http://php.net/enable-dl
enable_dl = On
I have just installed WampServer, and faced same problem. I have found solution, that works for me, it is ridiculously simple.
Disable PHP extension php_mysqli.
Restart WampServer, visit local phpmyadmin.
Enable php_mysqli back.
Repeat step 2.
After few page refreshes, remaining errors plates (about MySQL and sqli) had gone.
i tried hard by
installing the wamp again and again,
by checking the php.ini file,
by restarting the machine,
by replacing the index.php file,
but none works.
then i go to the wamp/temp and deleted all files and it works fine now.
I had path variable in windows set to some random version of php.
The fix was to update it and set it to the folder within my wampserver installation:
C:\wamp64\bin\php\php5.6.38
Then I realized this is wrong also for my specific case, and I should actually be running the script from within vagrant. Live and learn.
I had this issue because of a different reason:
Check the PHP Error Log(Get from the Wamp Tray -> PHP -> PHP Error Log.
I had a syntax error in the php.ini file while I was editing the file.
Check the log and clear the error. This will open your PhpMyAdmin properly.
Check your phpForApache.ini file's extensions. This file should be same as your php.ini file.

Categories