SQLSTATE[42000]: Syntax error or access violation: 1148 Unable to parse: use DB_Name;
I'm encountering an error while trying to connect to a MariaDB cluster using a load balancer IP in my Laravel application. The error message is: SQLSTATE[42000]: Syntax error or access violation: 1148 Unable to parse: use DB_Name;
Interestingly, I can connect to the same MariaDB instance using a standalone PHP script without any issues.
Here is the relevant configuration from my config/database.php file:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST_MYSQL', '127.0.0.1'),
'port' => env('DB_PORT_MYSQL', '3306'),
'database' => env('DB_DATABASE_MYSQL', 'forge'),
'username' => env('DB_USERNAME_MYSQL', 'forge'),
'password' => env('DB_PASSWORD_MYSQL', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
PDO::MYSQL_ATTR_LOCAL_INFILE => true,
]) : [],
],
Additional Information The connection works fine with a standalone PHP script. The issue seems to be specific to the Laravel application.
What I've Tried Verified that the .env file has the correct database connection settings. Cleared the configuration cache using PHP artisan config:cache. Checked the SQL modes in MariaDB to ensure they are compatible. Tested the database connection using Laravel's Tinker. Logged SQL queries to identify the problematic query.
Please or to participate in this conversation.