Database Configuration

revIgniter has a config file that lets you store your database connection values (username, password, database name, etc.). The config file is located at:

application/config/database.lc

The config settings are stored in a multi-dimensional array with this prototype:

put "localhost" into sDB["default"]["hostname"]
put "root" into sDB["default"]["username"]
put "" into sDB["default"]["password"]
put "databaseName" into sDB["default"]["database"]
put "mysql" into sDB["default"]["dbdriver"]
put "" into sDB["default"]["dbprefix"]
put TRUE into sDB["default"]["pconnect"] -- currently not implemented
put FALSE into sDB["default"]["dbdebug"]
put "" into sDB["default"]["dbRedirectOnError"]
put FALSE into sDB["default"]["cacheon"]
put "" into sDB["default"]["cachedir"]
put "utf8" into sDB["default"]["charset"]
put "utf8_general_ci" into sDB["default"]["dbcollat"]
put TRUE into sDB["default"]["cacheautodel"]

# SQLite DRIVER ONLY
put "" into sDB["default"]["options"]

# MYSQL AND THE POSTGRES DRIVER
# DEFAULT MYSQL: 3306, DEFAULT POSTGRES: 5432
-- put 3306 into sDB["default"]["port"]

# MYSQL DRIVER ONLY
put FALSE into sDB["default"]["useSSL"]

# THE FOLLOWING THREE VARIABLES ARE PART OF ENGINE CHANGES 4.6.4
# BE AWARE THAT THESE ARE NOT TESTED
# MYSQL DRIVER ONLY
put "" into sDB["default"]["dbSocket"]

# MYSQL DRIVER ONLY
put 20 into sDB["default"]["dbTimeout"]

# MYSQL DRIVER ONLY
put FALSE into sDB["default"]["dbAutoReconnect"]

The reason we use a multi-dimensional array rather than a more simple one is to permit you to optionally store multiple sets of connection values. If, for example, you run multiple environments (development, production, test, etc.) under a single installation, you can set up a connection group for each, then switch between groups as needed. For example, to set up a "test" environment you would do this:

put "localhost" into sDB["test"]["hostname"]
put "root" into sDB["test"]["username"]
put "" into sDB["test"]["password"]
put "databaseName" into sDB["test"]["database"]
put "mysql" into sDB["test"]["dbdriver"]
put "" into sDB["test"]["dbprefix"]
put TRUE into sDB["test"]["pconnect"] -- currently not implemented
put FALSE into sDB["test"]["dbdebug"]
put "" into sDB["test"]["dbRedirectOnError"]
put FALSE into sDB["test"]["cacheon"]
put "" into sDB["test"]["cachedir"]
put "utf8" into sDB["test"]["charset"]
put "utf8_general_ci" into sDB["test"]["dbcollat"]
put TRUE into sDB["test"]["cacheautodel"]

# SQLite DRIVER ONLY
put "" into sDB["test"]["options"]

# MYSQL AND THE POSTGRES DRIVER
# DEFAULT MYSQL: 3306, DEFAULT POSTGRES: 5432
-- put 3306 into sDB["test"]["port"]

# MYSQL DRIVER ONLY
put FALSE into sDB["test"]["useSSL"]

# THE FOLLOWING THREE VARIABLES ARE PART OF ENGINE CHANGES 4.6.4
# BE AWARE THAT THESE ARE NOT TESTED
# MYSQL DRIVER ONLY
put "" into sDB["test"]["dbSocket"]

# MYSQL DRIVER ONLY
put 20 into sDB["test"]["dbTimeout"]

# MYSQL DRIVER ONLY
put FALSE into sDB["test"]["dbAutoReconnect"]

Then, in your controller, to globally tell the system to use that group you would set this variable located in the config file:

put "test" into sActiveGroup

Note: The name "test" is arbitrary. It can be anything you want. By default we've used the word "default" for the primary connection, but it too can be renamed to something more relevant to your project.

Active Record

The Active Record Library is globally enabled or disabled by setting the gRigA["activeRecord"] variable in the database configuration file to TRUE/FALSE (boolean). If you are not using the active record library, setting it to FALSE will utilize fewer resources when the database libraries are initialized.

put TRUE into gRigA["activeRecord"]

Note: that some revIgniter libraries such as Sessions require Active Records be enabled to access certain functionality.

Explanation of Values:

Note: Depending on what database platform you are using (MySQL, Postgres, etc.) not all values will be needed. For example, when using SQLite you will not need to supply a username or password, and the database hostname will be the path to your database file. The information above assumes you are using MySQL.

SQLite PRAGMA Statements

The following handlers let you query the SQLite driver for internal data and modify the operation of SQLite.

rigDbSetPragma pPragma, pValue

Change SQLite PRAGMA settings. Example:

put "foreign_keys" into tPragma
rigDbSetPragma tPragma, 1

The result value of this handler is 0 or, in case the query was not successful, an error message where the first word is "Error:"

rigDbGetPragma(pPragma)

Query SQLite PRAGMA settings. Usage example:

if rigDbGetPragma("foreign_keys") is 0 then
	-- some code...
end if

This handler returns a PRAGMA value or, in case the query was not successful, an error message where the first word is "Error:"