codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: Unable to connect to the database when name contains word `export` #6621

Closed psuplat closed 2 years ago

psuplat commented 2 years ago

PHP Version

8.1

CodeIgniter4 Version

4.2.1

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli

Database

PostgreSQL

What happened?

Unable to connect to the database when database group name contains word export, even is it's only a partial name, ie. _exportsdata will also fail.

Steps to Reproduce

Define db group with word export in .env file:

database.exports_test.hostname = localhost
database.exports_test.database = dev_db
database.exports_test.username = postgres
database.exports_test.password = postgres
database.exports_test.DBDriver = Postgre
database.exports_test.DBDebug = FALSE
database.exports_test.schema = exports_test
database.exports_test.port = 5432

define this group in app/Config/Database.php:

public $exports_test= [
    'hostname' => '',
    'schema' => '',
    'username' => '',
    'password' => '',
    'database' => '',
    'DBDriver' => '',
    'DBPrefix' => '',
    'pConnect' => false,
    'DBDebug'  => (ENVIRONMENT !== 'production'),
    'cacheOn'  => false,
    'cacheDir' => '',
    'charset'  => 'utf8',
    'DBCollat' => 'utf8_general_ci',
    'swapPre'  => '',
    'encrypt'  => false,
    'compress' => false,
    'strictOn' => false,
    'failover' => [],
];

try to run a query against the db. You will receive You have not selected a database type to connect to error message

Expected Output

Query results

Anything else?

No response

kenjis commented 2 years ago

Thank you for reporting.

Is this because of database group name or database schema name ?

paulbalandan commented 2 years ago

I think this is because of DotEnv class replacing export to empty string during sanitization.

psuplat commented 2 years ago

group name. If I change the group name to expor, but keep the schema name it then works as it should

kenjis commented 2 years ago

This is a bug in DotEnv. A workaround is to set in the Config file.