Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter initial configuration
#1

(This post was last modified: 05-05-2020, 07:59 AM by imabot.)

Hi, I'm from CI3 and I try to migrate on CI4.

I'm following this tutorial : https://codeigniter.com/user_guide/tutorial/index.html

Initial configuration is not clear. I do not understand what I should do to get a proper configuration of CodeIgniter. Here are some of my interrogations :

I read the CI_ENVIRONMENT variable can be set in the .htaccess file and in the .env file. Where should I put the configuration ?
I read the baseURL variable can be set in /Config/app.php, and in the .env file. Where should I configure baseURL ?
I read the database configuration can be set in the /Config/database.php and in the .env file. Where should I configure the DB ?

I try to configure  the DB in /Config/database.php and in the .env file, but I can't get ride of this error : 
Quote:You have not selected a database type to connect to.
You have not selected a database type to connect to.
I can't figure out how to properly configure CI4 for development on a local apache server and for production on a remote apache serveur. 

I read the doc dozen of times, but I still don't understand the configuration philosophy of CI4. Any light is welcome.
Reply
#2

You have to set the data for the connection to the database on app / Config / database.php
Reply
#3

(This post was last modified: 05-05-2020, 11:16 AM by jreklund.)

It's recommended to set in .env, so you can have a different .env file on your severs.

Please note you need to rename/copy your env into .env - There need to be a . (dot).
Code:
CI_ENVIRONMENT = development
app.baseURL = 'http://skribbl.example.com/'
app.indexPage = ''
database.default.hostname = localhost
database.default.database = skribbl
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi
Reply
#4

(This post was last modified: 05-05-2020, 12:08 PM by jreklund.)

Quote:jreklund It's recommended to set in .env, so you can have a different .env file on your severs.

Ha, OK, that was not clear for me after reading the documentation.

Quote:Please note you need to rename/copy your env into .env - There need to be a . (dot).
Code:
CI_ENVIRONMENT = development
app.baseURL = 'http://skribbl.example.com/'
app.indexPage = ''
database.default.hostname = localhost
database.default.database = skribbl
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi

So the database configuration in the /Config/Database.php is not used, right ?

Hum it's not working I still have the following error :

Code:
InvalidArgumentException

You have not selected a database type to connect to.
 
When I look at the arguments of  CodeIgniter\Database\Database->load ( arguments ), this is the arguments set in /Config/Database, not the parameters set in .env.
Reply
#5

Can you post your .env file here?

.env overrides your settings in /app/Config/(all files)
Reply
#6

(This post was last modified: 05-05-2020, 12:25 PM by imabot.)

(05-05-2020, 12:10 PM)jreklund Wrote: Can you post your .env file here?

.env overrides your settings in /app/Config/(all files)

OK, .env overrides settings !!! Everything is clear now. 

By the way, it works, I reverted the file /Config/Database.php. (As it was not working, I try many options, and I probably changed something that prevent connecting to MySQL). Let's try PDO now !

Thank you for your help.
Reply
#7

PDO are not ported yet, so you can't use that driver.
https://codeigniter.com/user_guide/intro...ments.html
Reply
#8

(This post was last modified: 05-05-2020, 12:46 PM by imabot.)

(05-05-2020, 12:27 PM)jreklund Wrote: PDO are not ported yet, so you can't use that driver.
https://codeigniter.com/user_guide/intro...ments.html

This is probably why it was not working! Do you know configuration settings for PDO is explained in the documentation : https://codeigniter.com/user_guide/datab...figuration

Quote:Some database drivers (such as PDO, PostgreSQL, Oracle, ODBC) might require a full DSN string to be provided. If that is the case, you should use the ‘DSN’ configuration setting, as if you’re using the driver’s underlying native PHP extension, like this:

Code:
// PDO
$default['DSN'] = 'pgsql:host=localhost;port=5432;dbname=database_name';
Reply
#9

Okay, that's wrong at this time. CI4 user guide are based on CI3, so must have been missed.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB