PDOException in my Laravel application, despite having pdo_mysql installed - php

I am trying to run a new Laravel app on my sever but I am getting the following error:
QueryException (SQL) could not find driver (SQL: select * from
settings limit 1)
Using the debugbar I can see the error is for PDO: LOG.error:
PDOException: could not find driver in
/home/mysite.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:
What doesn't make sense is that I actually already have PDO installed, I know this because I ran the first php artisan migrate and it created all the tables in my MYSQL DB fine.
I have ran php -m | grep mysql to verify what mysql related PHP extensions I have:
$ php -m | grep mysql
mysqli
mysqlnd
pdo_mysql
I should note that PHP can use MySQL as I have a Wordpress blog running on the same server fine.
I have already tried clearing the cache and updating composer packages, I have also completely removed doctrine/dbal and reinstalled.
Update: If I remove the package doctrine/dbal and clear the caches, I still receive an error about PDOExceptions:
Illuminate\Database\QueryException could not find driver
/home/mysite.com/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php#68

Try this:
composer update
composer require doctrine/dbal
It looks like you have a missing dependency
Notice:
You might need to comment out the following in your php.ini file.
;extension=pdo_mysql.so
stackoverflow.com/a/42561002/2109233 source

Related

Symfony 6 / Doctrine - An exception occurred in the driver: could not find driver

I tried to setup my symfony project, everything was well, since I tried to create the doctrine database.
I written my DATABASE_URL in the .env file, that is correct, well I think so, but nothing works, either my local xampp server or my web server.
I get always the same error:
[critical] Error thrown while running command "doctrine:database:create". Message: "An exception occurred in the driver: could not find driver"
In ExceptionConverter.php line 119:
An exception occurred in the driver: could not find driver
In Exception.php line 30:
could not find driver
In Driver.php line 28:
could not find driver
It looks like you may have not enabled the pdo_mysql extension in your php.ini file.
Try to uncomment the ;extension=pdo_mysql line inside your php.ini.
Beware, your php console may use a different php.ini file than the one that runs your application.
I am also a beginner on Symfony and I use ubuntu.
I followed the below steps-
I first wrote in my terminal the command: symfony check:requirements to know what was wrong.
I got confirmation that my pdo_mysql had missing drivers and as I'm using php 8.2, so I installed MySQL for php8.2.
In the terminal, type the command sudo apt-get install -y php8.2-mysql
and then retype the command: php bin/console doctrine:database:create for the creation of the database.
Let me know if it works.
New to symfony, I also had this problem.
I needed to get an .env.local file from another developer, and I did not realize that the .env.local file needed to go in to the app/ directory.
So that the app/.env and app/.env.local are both in place.
It was only then that symfony was able to pick up the correct DATABASE_URL

Issue with install and setup mongodb into m1 macbook

I have an issue with connecting php(valet) and MongoDB. I tried to install MongoDB with pecl and command sudo pecl install mongodb and brew install mongodb and all time I get some errors during the install process:
In file included from /private/tmp/pear/temp/mongodb/src/MongoDB/Cursor.c:18: /opt/homebrew/Cellar/php#8.0/8.0.17/include/php/ext/spl/spl_iterators.h:151:4: error: unknown type name 'pcre_cache_entry' pcre_cache_entry *pce; ^ 1 error generated. make: *** [src/MongoDB/Cursor.lo] Error 1 ERROR: make' failed`.
But when I run mongo --version I get:
and I install MongoDB Compass and as you can see, I can connect to the database and write into it:
But when I try out to install laravel package jenssegers/mongodb I get these errors: I tried with --ignore-platform-req=ext-mongodb flag but then it install package but it didn't work, I get this error: Error: Class "MongoDB\Driver\Manager" not found.
Finally, I find out a great package that helps me in this! This repo saves me a ton of time and debugging! Thank you shivammathur!
Hey I also had the same problem. A good alternative is to also follow with this article if you want to stick with pecl https://freek.dev/2151-fixing-the-dreaded-pcre2h-file-not-found-error-when-installing-imagick

Getting "could not find driver" when working with Redis job in Laravel

I installed my Laravel app on Ubuntu system and already installed pdo_mysql and mysqli and all extension.
Code is working fine when I run the job without Redis driver, but not working fine when using Redis driver.
I am getting below error and it's very strange for me:
could not find driver (SQL: insert into failed_jobs (connection, queue, payload, exception, failed_at) values (redis, default, {"type":"job","timeout":null,"tags":{},"id":"1","data":{"command":"O:26:\"App\Jobs\SapProductSyncJob\":8:{s:9:\"user_data\";a:1:{s:7:\"user_id\";i:3;}s:6:\"\u0000*\u0000job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";N;s:7:\"chained\";a:0:{}}","commandName":"App\Jobs\SapProductSyncJob"},"displayName":"App\Jobs\SapProductSyncJob","timeoutAt":null,"pushedAt":"1584684956.0182","job":"Illuminate\Queue\CallQueuedHandler#call","maxTries":null,"delay":null,"attempts":2}, PDOException: could not find driver in /home/path/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
You should download, install and run redis-server in your server: Download Redis
Or alternatively you can use database as a storage for your jobs by editing .env file:
QUEUE_CONNECTION=database

could not find driver (SQL: select user_id

I am getting this error
could not find driver (SQL: select user_id...
]
I've looked at other related questions and tried the suggestions but I am still getting the same error.
My PHP.ini has extension=php_pdo_mysql.dll
I've added "doctrine/dbal": "^2.5",
I've also tried clearing cache, config, dump auto load etc.
phpinfo() shows there are no PDO drivers.
Previously my phpstorm was pointing at a PHP installation that didn't have extension=php_pdo_mysql.dll enabled but I am still getting the same error even after pointing it to the correct PHP folder.
You need to install PDO drivers first and if it did not solve your problem then below is the issue I have faced before maybe that will help.
sudo apt-get install php5.6-mysql/php7.2-mysql
You also can search for other database systems.
You also can search for the driver:
sudo apt-cache search drivername
Then Run the cmd php artisan migrate
You can also try:
sudo apt-get install php-sqlite3
also check the path for php-cli
If you can, run :
composer update
composer require doctrine/dbal
It looks like you have a missing dependency
Edit:
You might need to comment out the following in your php.ini file.
;extension=pdo_mysql.so
Taken from this post: Laravel 5 PDOException Could Not Find Driver . I think I had to do something exactly like this when setting up laravel on digital ocean.
There must be Query like this one in the code implode inside SQL code. check the variable $mistakeIdArr should not be empty.
$sql = "Select * from `mistake` where `id` in (".implode(',',$mistakeIdArr).")";
I have also checked in my code the PDO is enabled or not
if (extension_loaded('pdo')) { echo "pdo enable";die; }else{ echo "not enable";die;}

I can not make yii migration

I tried to work with yii basic migrations. yii migrate/create is working, yii migrate - not.
I use command php yii migrate. I get the following message:
Exception 'yii\db\Exception' with message 'could not find driver'
in ../basic/vendor/yiisoft/yii2/db/Connection.php:547
I have found advice that I need to add some files from advanced yii to my basic. I do not know what should be done exactly.
You should install extension to your php of DB, which you are using. In case it is already installed, make sure that it is properly turned on in your php-cli settings.
For example, in case you are using Ubuntu and php5-fpm you can run
sudo apt-get install php5-mysql

Categories