Its been a while since I said Hi so I’d like to take the opportunity now . I have an issue with a fresh clone on my new machine. I (obviously) did not account for this problem when I started my project last year. I will do my best to outline the current state of my problem as I am rather stuck.
Problem I’m experiencing: I have created a rather handy-dandy custom Yii command that loops over the tables in my PostGRES database and generates the corresponding models. I also have one for the controllers. These scripts work perfectly fine. My issue is that I recently build a new computer and discovered that when I attempt to run the command from that machine, I am getting a PDOException from Connection.php, line 648 “Could not find driver”. However, my laptop is still capable of running this command without the issue. I am able to execute REST queries from postman to my API project. However, the console application (of which I am on the same branch with no code changes whatsoever) does not work. I have attempted to eliminate any low-hanging issues (running init & composer install, etc)
I believe the issue might be a configuration issue that I must have solved on my laptop but now do not have the bash history to see what I did to make it work in the first place. e.g. locally configuring PHP or something. I am not entirely sure where the issue resides.
So with that being said, my environment is configured as such:
I use Docker & Docker-compose to build my project.
It builds fine and docker compose up -d works perfectly.
I mount an src directory to /var/www/html/src with rw
I attempt to run: ./yii model/generate-models --exclude-tables=user, profile
Just to reiterate, even though I am not using the gii/model tool, my custom command does, and it performs the job I need it to perfectly.
When I run it from the new comp however, I receive the PDOException: “Cant find driver”. I have been trying to step through the code (Connection.php:637)(Error thrown at 648) using xdebug, but to no avail.
./yii model/generate-models --exclude-tables=user ─╯
Exception 'yii\db\Exception' with message 'could not find driver'
in /home/edjimucator/Projects/sellario-api/src/vendor/yiisoft/yii2/db/Connection.php:648
Caused by: Exception 'PDOException' with message 'could not find driver'
in /home/edjimucator/Projects/sellario-api/src/vendor/yiisoft/yii2/db/Connection.php:722
Stack trace:
#0 /home/edjimucator/Projects/sellario-api/src/vendor/yiisoft/yii2/db/Connection.php(722): PDO->__construct()
#1 /home/edjimucator/Projects/sellario-api/src/vendor/yiisoft/yii2/db/Connection.php(637): yii\db\Connection->createPdoInstance()
I know this is something silly on my behalf but I am a bit baffled by it. I greatly appreciate your time for reading this far and would like to thank everyone before-hand for any contributions helping me suss out the issue. I am happy to post whatever code is needed.
I promise to not rule this out, I just read the stackoverflow link. I promised to show code as needed and I intend to follow through with that promise because (as I see it) anyone willing to help me sort this out certainly deserves it. I also would love to do my best to not give anyone a sense of condescension by lack of tone through text. I am 100% baffled by this problem and hope to reconcile the mistakes I made last year with the problem I have now.
I also used php -m (after exec’ing into the container) to verify that the driver is installed and enabled. I have also vim’d the pgsql.ini file to confirm that it is enabled.
I am still stumped why it works from my laptop. I recloned the project and checked out the exact same branch for sanity reasons. I still believe the issue resides at the local environment config because of that fact. I believe that because it works from my laptop but not my newly created computer because of a local config I might have lost. I have attempted to composer install, and the code definitely dies at the Connection.php file when I run the code. I had my cofounder attempt to clone the project & branch, he is getting the issue himself.
Its my belief that I’m forgetting an essential composer command. When I started the project (boilerplate in this instance) it was years ago. I think I have a project that references a global composer config that I can no longer find. @samdark I built the foundations of this boilerplate when (I believe) the fxp-bowser assets were involved. I will look into it though. I just feel like Im trying to debug in the dark.
For reference:
I am able to make REST API application requests successfully that use the same vendor folder
I am able to connect to the running instance using the credentials in the console/config/main.php “db” component
The same “db” component configuration is used by the API application.
And currently, my laptop does run the command successfully. That leads me to believe that the problem exists outside of docker, and the project for that matter.
I’m also able to connect to the running instance using PGmodeler as my EER diagram of choice.
@tri - Thank you for that stackoverflow question, there are quite a few things I havent tried yet. I will post the results as soon as I get a chance to attempt them.
@samdark If by now you’re thinking: It’s time for a solid commit to fix these problems once I solve them. I couldn’t agree more. I will also keep the thread updated in case this becomes a problem for anyone going forward.
Again, I’d like to say thank you for anyone attempting to solve a problem I coded myself into.
So as it turns out, @tri you were right. I kept checking the INI file and saw that PostGres was installed, I did have it enabled but I did not have its driver enabled in my local php.ini config … I saw it in mods_available, and when I VIM’d the file I saw that it was uncommented. I thought that meant it was enabled. It wasnt until I checked /etc/php/php.ini that I noticed it was commented out.
Thank you so much for the help. I’m going to add a configuration script to my custom init script in the project that configures it going forward.