Dessauges Antoine
Dessauges Antoine

Reputation: 593

Laravel 5.5 can't connect to database

I have a larvael and I want it to make it in production. I have a server hosting and database on infomaniak.com.

I have upload all my file and I get a SQL timeout error :

SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from characters where checked = 1 order by RAND() limit 1)

I have an other Laravel website on infomaniak and don't have this problem. I have check my .env file, my /config/database file and try php artisan config:clear or php artisan cache:clear. I also try to dump DB:connection() and the connection information are right.

I can connect to my homestead database in local and work fine. But when I try to connect to the SAME database than my other website with the same .env file and still have the timeout error.

How can I fix this ? Are there a way to clear another cache ? Completly lost :/

EDIT :

If i try :

if(DB::connection()->getDatabaseName()) {
    echo "Yes! successfully connected to the DB: " . DB::connection()->getDatabaseName();
}

The page return Yes! successfully connected to the DB: db_name

EDIT 2 :

I just see my hosting server is in PHP 5.6 but it say that's my website is in PHP 7. Really confusing but maybe this informations is important (have another laravel on this server and works like that)

Upvotes: 1

Views: 1410

Answers (1)

JoseSilva
JoseSilva

Reputation: 517

Your problem is the php version, if you're using laravel 5.5 then your host must have php 7 installed.

See the oficial docs here

Upvotes: 2

Related Questions