Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel multiple database can not connect #24

Open
gbekura opened this issue Jul 5, 2024 · 0 comments
Open

Laravel multiple database can not connect #24

gbekura opened this issue Jul 5, 2024 · 0 comments

Comments

@gbekura
Copy link

gbekura commented Jul 5, 2024

We are encoutering troubles with connecting platform sh Databases to laravel.

for example we have services yml:

# The name of the service container. Must be unique within a project.
db5:
    type: mariadb:11.2
    disk: 2048
    configuration:
        schemas:
            - archfix_ibc
            - archfix_static
        endpoints:
            mysql:
                default_schema: archfix_ibc
                privileges:
                    archfix_ibc: admin
            mysql2:
                default_schema: archfix_static
                privileges:
                    archfix_static: admin

And app relationships:

relationships:
    mysql: 
        service: db5
        endpoint: mysql
    mysql2: 
        service: db5
        endpoint: mysql2

database.php db configs:

        'mysql2' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST_2', '127.0.0.1'),
            'port' => env('DB_PORT_2', '30001'),
            'database' => env('DB_DATABASE_2', 'archfix_static'),
            'username' => env('DB_USERNAME_2', 'user'),
            'password' => env('DB_PASSWORD_2', ''),
            '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'),
            ]) : [],
        ],
        
        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            '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'),
            ]) : [],
        ],

And it won't connect to the database. User manual lacks information about non standard cases.

I assume that it only works if relationship is called database and laravel app has only one database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant