Skip to content
rileywiebe edited this page Oct 28, 2011 · 3 revisions

Databases

Many applications will use some form of database. MySQL is currently the only database that has a built in driver, but others may be used.

Basics

There are two ways of connecting to a database.

  1. Connect to the database when the application starts.
  2. Connect to the database in a specific method.

Lots of applications will use a database throughout the entire program and will benefit from connecting right away.

Autoload Database

To autoload a database all the database's information will be stored in the /application/config/database.php file.

  • host - Your host name, usually localhost.
  • name - The database name.
  • username - The username to connect to the database.
  • password - The password used to connect to the database.
  • table_prefix - Not required. Can be used for apps which have the same prefix. You must call this yourself, it is not automatically called.

The database connection will not run until the $database has been set to true in /application/config/autoload.php

Once the $database variable has been set to true, the framework will attempt to connect to the database automatically when the application starts.

Connecting to database in method

...

Database Queries

To make calls to the database you must load the FDatabase library.

Database calls are used using FDatabase::query('');

Clone this wiki locally