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:
- hostname - The hostname of your database server. Often this is "localhost".
In case you use SQLite set this variable to the database file path like:
For revIgniter to be able to access your SQLite databse the application/db folder must be set such that it is writable and executable (777),put gAPPPATH & "db/myDatabase.sqlite" into sDB["default"]["hostname"]
your database file must be writable (666). - username - The username used to connect to the database.
- password - The password used to connect to the database.
- database - The name of the database you want to connect to.
- dbdriver - The database type. ie: mysql, postgre, etc. Must be specified in lower case.
- dbprefix - An optional table prefix which will added to the table name when running Active Record queries. This permits multiple revIgniter installations to share one database.
- pconnect - TRUE/FALSE (boolean) - Whether to use a persistent connection (currently not implemented).
- dbdebug - TRUE/FALSE (boolean) - Whether database errors should be displayed.
- dbRedirectOnError - The local URI ("myController/myHandler") to be used for a redirect in case a database error occurs. Providing a handler name is optional. Note: You need to set dbdebug to FALSE for this to work.
- cacheon - TRUE/FALSE (boolean) - Whether database query caching is enabled, see also Database Caching Library.
- cachedir - The absolute server path to your database query cache directory.
- charset - The character set used in communicating with the database.
- dbcollat - The character collation used in communicating with the database.
- cacheautodel - TRUE/FALSE - Whether to delete the query cache on write queries.
- options - A comma delimited list of SQLite options. Can be empty or can contain "binary", "extensions" or both.
- port - The database port number. Currently only used with the Postgres driver. To use this value you have to add a line to the database config array.
put 5432 into sDB["default"]["port"]
- useSSL - TRUE/FALSE Whether to use SSL for the connection or not.
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, "ON"
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:"