Welcome Guest, Not a member yet? Register   Sign In
Unable to connect to the database. Using Postgre Driver
#1
Question 
(This post was last modified: 04-12-2024, 10:24 AM by warcooft.)

I have followed the documentation regarding database configuration. https://codeigniter.com/user_guide/datab...tion.html#

here my db config:

PHP Code:
public array $default = [
        'DSN'          => 'Postgre://username:password@hostname:5432/database?charset=utf8&connect_timeout=5&sslmode=1',
        'hostname'    => 'localhost',
        'username'    => 'postgres',
        'password'    => '123456',
        'database'    => 'playground_db',
        'DBDriver'    => 'Postgre',
        'DBPrefix'    => '',
        'pConnect'    => false,
        'DBDebug'      => true,
        'charset'      => 'utf8mb4',
        'DBCollat'    => 'utf8mb4_general_ci',
        'swapPre'      => '',
        'encrypt'      => false,
        'compress'    => false,
        'strictOn'    => false,
        'failover'    => [],
        'port'        => 5432,
        'numberNative' => false,
        'dateFormat'  => [
            'date'    => 'Y-m-d',
            'datetime' => 'Y-m-d H:i:s',
            'time'    => 'H:i:s',
        ],
    ];

  

and then i got this error:

Unable to connect to the database.
Main connection [Postgre]: pg_connect(): Unable to connect to PostgreSQL server: invalid sslmode value: "1"

Here details:
https://postimg.cc/bGf6Kmfw

I have applied the above configuration to the .env file in Codeigniter 4.4.8 and it works fine, but why doesn't it work in Codeigniter 4.5.0? Previously I tried to apply it in .env exactly with version 4.4.8 but it didn't work. Lastly, I configured it in the Config\Database.php file and it also didn't work.
Reply
#2

[quote pid="417831" dateline="1712941958"]
PHP Code:
    //    * Sample database connection for Postgre.
    //    *
    //    * @var array<string, mixed>
    //    */
      public array $postgre = [
          'DSN'        => '',
          'hostname'  => 'localhost',
          'username'  => 'postgres',
          'password'  => '123456',
          'database'  => 'playground_db',
          'schema'    => 'public',
          'DBDriver'  => 'Postgre',
          'DBPrefix'  => '',
          'pConnect'  => false,
          'DBDebug'    => true,
          'charset'    => 'utf8',
          'swapPre'    => '',
          'failover'  => [],
          'port'      => 5432,
          'dateFormat' => [
              'date'    => 'Y-m-d',
              'datetime' => 'Y-m-d H:i:s',
              'time'    => 'H:i:s',
          ],
      ]; 

[/quote]
Reply
#3

The error should be quite self-explanatory, "1" is not a valid value for sslmode. Try:
       
Code:
'DSN'          => 'Postgre://username:password@hostname:5432/database?charset=utf8&connect_timeout=5&sslmode=allow',
Reply




Theme © iAndrew 2016 - Forum software by © MyBB