I have two database connections. One is postgresql (no problem) and the other is mysql.
I' ve been able to connect to the database and dump data from a file with this command:
cat cosmo.sql | docker exec -i edb9f60b1531 /usr/bin/mysql -u sail --password=password testing
But when I try to use eloquent it hangs up. This is a test I did:
use App\Models\Access;
Access::find(1);
Illuminate\Database\QueryException SQLSTATE[HY000] [2006] MySQL server has gone away (Connection: mysql, SQL: select * from `access` where `access`.`id` = 1 limit 1).
This is from my .env file:
DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432
DB_DATABASE=entropia_api
DB_USERNAME=sail
DB_PASSWORD=password
DB_CONNECTION2=mysql
DB_HOST2=mysql
DB_PORT2=3306
DB_DATABASE2=testing
DB_USERNAME2=sail
DB_PASSWORD2=password
This is my model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DisposAcceso extends Model
{
use HasFactory;
protected $connection = 'mysql';
protected $table = 'access';
}
I haven't changed config/database.php, so I have the default connections.