HansSchouten / Laravel-Pagebuilder

A drag and drop pagebuilder to manage pages in any Laravel project
https://www.phpagebuilder.com
MIT License
783 stars 182 forks source link

Problem connecting to database #86

Closed bUrinot closed 3 years ago

bUrinot commented 3 years ago

Hello there! Thanks for the plugin I'm trying to install a Laravel Pagebuilder in a new Laravel project (8.27) and all the time i get a PDOException Error PDOException SQLSTATE[HY000] [2002] Connection refused vendor/hansschouten/phpagebuilder/src/Core/DB.php:32 ` $this->pdo = new PDO(

        $config['driver'] . ':host=' . $config['host'] . ';dbname=' . $config['database'] . ";options='--client_encoding=" . $config['charset'] . "'",

        $config['username'],

        $config['password'],

        [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]

    );

'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'),
        ]) : [],
    ],

`

This in pagebuilder.php ` 'storage' => [

    'use_database' => true,
    'database' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST').':'.env('DB_PORT',3306),
        'database'  => env('DB_DATABASE'),
        'username'  => env('DB_USERNAME'),
        'password'  => env('DB_PASSWORD'),
        'charset'   => 'utf8',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix'    => 'pagebuilder__',
    ],
    'uploads_folder' => storage_path('app/pagebuilder/uploads')
],

`

and this in .env `

DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=sitebuilder DB_USERNAME=root DB_PASSWORD=root DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock `

I'm sure is a newbie thing but if you can give a hint on how to fix it

HansSchouten commented 3 years ago

Is the database in your regular Laravel installation working? And is it also working without the DB_SOCKET setting? This part is ignored by the pagebuilder package at the moment as it makes its own connection.

bUrinot commented 3 years ago

Hey. thanks for responding. ok, it was that! I have added the unix_socket at the PDO and it's working now...

$this->pdo = new PDO(

$this->pdo = new PDO(
        $config['driver'] . ':host=' . $config['host'] . ';unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=' . $config['database'] . ";options='--client_encoding=" . $config['charset'] . "'",
        $config['username'],
        $config['password'],
        [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
    );

` Now I'll be able to check this repo as it seems amazing thanks