Symfony 5 exception Could not find driver - php

I am making my first app with Symfony and when i setup my database (doesn't matter if it's postgresql or mysql).
I have an error "could not find driver" three time.
One in PDOConnection.php line 38.
Other in Exception.php line 18.
And last one in AbstractMySQLDriver.php line 128.
What i made : i check the php path i also check all the extensions. I check if i fill correctly .env and i check those folders.
PHP version : 7.4
And mysql in docker containers: mysql:5.7.
I really have no idea what to do now
UPDATE:
The problem (for me) was the command php bin/console doctrine:database:create
if you have the same problem try symfony doctrine:database:create

do you use .env file? I have same problem and after a day of disable/enable pdo without any effect, i found that symfony auto add a line to my .env file:
DATABASE_URL=postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=11&charset=utf8
That make my database url wrong and error not found pdo fire because of postgresql not mysql

Apparently you use Docker, but in your question you mentioned Windows cmd. I suppose, you check PDO extension in your host system, not in container. You need to log into your Docker PHP container and check it there. In Windows Desktop version of Docker there is a button near each container to open command-line interface. You also can use command:
docker exec -it <here goes your container name>
To find out what your container name is, you can use command
docker ps
UPDATE:
To start your project not in Docker, bun on Windows-host itself, you can use very helpful mini-server, provided by Symfony. Run this command inside your project directory:
symfony serve
It will start local server, available by default at address https://127.0.0.1:8000/.
However, keep in mind, that if your project requires database, you will need to have MySQL Server for Windows installed on your host system too.

Related

Why can't I run phpinfo() in my docker container?

I am trying to get a connection between my php-fpm docker container and an RDS Postregsql. I found that I was getting an error in my php application "call to undefined function pg_connect()". So I thought that maybe the issue was that I didn't have pgsql driver enabled in my php.ini. So I tried to enable it, by first adding a line to my Dockerfile, rebuilding the image, then I brought down the container and brought it up again. But I am getting the same error "call to undefined function pg_connect(). So I'd like to run phpinfo() in the container to see if the pgsql driver is loaded. I tried to run it by using docker exec 4822 /bin/bash to open a cli to the container, but the host cli just comes back with a $. How can I run phpinfo() in the container so I can figure out why $DB2 = $this->load->database('postgres', TRUE) is failing with the above error? I am using Codeigniter and here is the connection array:
enter code here
enter code here
Sorry I can't get the format going. Anyway, here is the dsn
'dsn' => 'jdbc:postgresql://imagesdatabase.cwymdn16cxes.us-east-1.rds.amazonaws.com:5432/postgres'
From the $ prompt:
php
should start the PHP process. Then:
<?php phpinfo();
will display phpinfo() output. You will need to end the php process with a Control-D and then all output should be displayed.
Follow this https://www.php.net/manual/en/features.commandline.interactive.php
This will help you, how to use interactive command line PHP.
If DockerImage is based on PHP or has PHP installed in docker container then you can use this feature. What you need to do in docker terminal is run following command
$ php -a
Interactive shell
php > echo 5+8;
13
Well I finally realized that since my under development is php why not just insert phpinfo() into the start up. I did that and it works great! All that effort just to confirm that the pgsql driver is not loaded! At this rate it will take me the rest of my life to finish my application 😀.

Debugging with Docker Compose remote interpreter: db container unknown

I am currently trying to debug my tests in PhpStorm with a docker-container as remote interpreter. The problem I am facing is that, though I can connect to the remote interpreter and execute my code on it, the container seems to be unaware of the other containers from the compose file. Unlike normally he is unable to connect to the database, which runs in another container (host=mysql).
Does anybody had the same issue before and found a solution?
Are you setting up your remote interpreter as Docker or Docker Compose?
In PhpStorm go to Preferences -> PHP -> CLI Interpreter -> ... and Check if you have Docker Compose or Docker section right under the name of Interpreter. If it's not Docker Compose, add a new Interpreter and make sure to chose Docker Compose for this one

php artisan migrate stuck at the beginning of the command

[MacOS 10.14.0]
When I create a new project (Laravel new blog)
Then create a table in MySQL (create database blog)
And then update my .env file with the correct userame, password and database.
After creating a project, I will run php artisan migrate
But my terminal stays empty, I can type in my terminal. But it won't do anything.
My storage/logs folder is empty.
I have 2 default migrate files in my database/migrations folder.
php migrate list works
What can it be?
For me it helped just to restart local database.
After a lot of trial and error, I found out that there was something wrong with my MySQL server. I reinstalled MySQL with brew. The latest version of 8 and the latest version of 5.7.*. Both didn't work, because of the following conflict: Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/lib/plugin/caching_sha2_password.so, 2): image not found.
So the whole time, everything in my .env file was correct but my MySQL was broken. I also confirmed that by trying to connect with the app 'Sequel Pro'. And as I thought, it gave me the same conflict.
How I fixed the problem:
Remove all MySQL/MariaDB packages via brew (if you have installed them with brew like me)
Install MySQL Community Server 5.7.* from the official mysql.com website (you can google that file).
Add MySQL to your path export PATH=$PATH:/usr/local/mysql/bin
Go to: System Preferences -> MySQL -> press 'Start MySQL Server'
Change your temporary password with a new one mysqladmin -uroot -p[temporary password] password '[new password]'
Good luck! 👍
EDIT FEBRUARY 26 2019:
I found a problem with changing the random generated password. I was using MySQL Community Server 5.7.25 and the random generated password was: _>9mxWc9a!0.. When I was trying to change the default password with the command above. I was given the following error:
-bash: !0: event not found
If you have the same error as I did or something similar, try the following:
Enter the following command in your terminal: mysqladmin -uroot -p password '[new password]'
When you press enter, it will ask you for a password. Now enter the random generated password that was given to you by the MySql Community Server at installation in a prompt.
It should be working now! 😊
If you're using Docker and getting this error on the host machine, try running the migration in the container cli.
did you connected the laravel project to the database from .env file ?
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=DATABASE_NAME
DB_USERNAME=DATABASE_USERNAME
DB_PASSWORD=DATABASE_PASSWORD
Laravel 5.8 with SQLite.
My problem wasn't with larvel but with DB browser for sqlite. I had to open and close the program for the migrate to finish its process.

Edit MySQL table in a Symfony project hosted [SOFTACULOUS]

I'm coding a Symfony project and I should host it on a server that make me install Symfony by Softacolous (I can't use a shell). So, I can't understand how make an edit on the online DB.
Can you help me?
Use cPanel's Remote MySQL to enable access from your local PC and run:
php bin/console doctrine:schema:update --force --env=prod
To update your database from your code.
Also you dont need to install symfony via Softacolous, just upload your local files via ftp

Mysql Server running but Artisan in Laravel project doesn't think so

So, I have recently installed Mysql Server in my Macbook (Mac OS 10.11) and I also installed Mysql Workbench and it works great!
The problem comes when I want to migrate form a Laravel Project using Php Artisan, every time I run the php artisan migrate command it return the following error
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
I also noticed I have to mysql installations i the following paths:
/usr/local/mysql
/usr/local/mysql-5.7.13-osx10.11-x86_64/ (this is the one I am using)
I placed in the .bash_profile a PATH to the new one (5.7.13) like this:
export PATH=${PATH}:/usr/local/mysql-5.7.13-osx10.11-x86_64/bin/
Do you guys know how can I fix this? Thank you for any help!
Path to the binary doesn't matter, in this case it's looking for a MySQL socket file.
Find your socket file (find / -name mysql.sock)
Ensure this path is set in my.cnf used by your PHP (you can run php -i |grep pdo_mysql.default_socket to see the default path)
As a workaround, you could set a symbolic link from 1 to 2 (eg. ln -s /usr/local/mysql/var/mysql.sock /tmp/mysql.sock) but ideally you want to set a correct path for PDO (or whatever MySQL extension you are using for PHP)

Categories