phpmysqllaravelplanetscale

Laravel Planetscale can migrate but can't query it show SQLSTATE[HY000] [2002]


I'm having a bit of trouble with my Laravel version 8.0 and PlanetScale connection. I've got everything configured in my .env file, including the certificate installation, and I can migrate tables to the database just fine. However, when I try to query the database, I keep getting an error message that says Illuminate\Database\QueryException.SQLSTATE[HY000] [2002] (SQL: select * from company_user)

These are the .env configuration I copied from planetscale

DB_CONNECTION=mysql
DB_HOST=aws.connect.psdb.cloud
DB_PORT=3306
DB_DATABASE=business_directory
DB_USERNAME=<username>
DB_PASSWORD=<password>
//cacert.pem is inside the root directory
MYSQL_ATTR_SSL_CA=cacert.pem

I've tried troubleshooting this issue on my own, but so far nothing has worked. I've double-checked all of my configuration settings and made sure that everything is correct, but I still can't seem to get it to work.

Has anyone else experienced this issue before? If so, do you have any suggestions for how to fix it? Any help would be greatly appreciated!

Thanks in advance.

PS. I have tried migrating tables, insert and query data from my localhost it work just fine.


Solution

  • To leave a solution for people who might face this issue in the future this is the solution that solved my problem.

    Planetscale require window user to download SSL certificate on our own. and I did download the SSL certificate but placed in the wrong folder. Instead of placing in the root directory, the cacert.pem file should be placed in public folder.

    //cacert.pem should be in public folder instead of root folder.
    MYSQL_ATTR_SSL_CA=cacert.pem