I’m having a strange issue with my database MySql connection, that seems to be failing on one specific occasion.
I’m running a Yii2 framework application (basic) on Xampp on my local machine, using PhpMyAdmin for the MySQL Database.
I’ve got no problem connecting with the db on my site (127.0.0.1:8080/yii-platform/web) or even via “mysql -u root -p”, but my php yii commands in the terminal give an error. So I can’t do any migrations, commands or anything that accesses the database from there (which is why I’ve been creating all my tables with sql queries in PhpMyAdmin).
The strange thing is that this connection is also using the configuration of the db-connection I have in the Yii app, which is working perfectly on the site. I also know the username and password are correct.
I’m sorry, I uploaded the wrong image. The error is about whatever user is filled in on the db dsn. I changed the image in the original post so that both say “root”.
How do I see which $config is used in the “yii script” ? I’ve noticed I’ve got a $config in another file called config > “web.php” (this is actually the one I’ve been expanding with routes and stuff) and also a $config in “console.php”, but I don’t understand why I started with two different $configs.
The fact that my site works and has access to database (with read, write, delete, update possibilities, so he must be able to login with username and password) makes it hard to pin down where the issue lies. Could it be something very specific with using the commands in terminal?
But usually both of them share the same config file for db connection ('db.php') which is included in 'web.php' and in 'console.php'. The db connection should work in both of them, or should fail in both of them.
This is from the error message.
I’m not familiar with XAMPP, but I guess you are using XAMPP-VM and your web site is working on a virtual machine. Am I right?
The error message seems to tell that you are trying to run the console app in the host machine. But I think it should be run on the VM. Could you try to run the yii command in the VM?
You were right that I’m using a XAMPP-VM, and I had been having issues getting into the terminal of this VM.
Finally I managed to get in, and I ran the command without issues! I checked in the database and I can delete records. So it worked, thank you very much!
For anyone with the same or a similar issue, what I did: