Menu

Configuring a Connection

DataExplore

Data Connections are set up in the classes folder. Each connection to a database for a particular type of data source (e.g. mySQL, Access) is stored in the class for that type.

To set up new mySQL connections, for example, open the /classes/mySqlConn.class.php file and add each separate database connection as a function:

example:

function test() {
$this->db = new mysqli('hostname',
'user',
'password',
'mydatabase'
);

}

When the test() method is called from the child class (mySqlObject.class.php), a connection to the database will be made and stored in the class property $this->db.

This structure will allow you to have several connections configured and then just call on them when instantiating the child class with the second parameter.

$obj = new mySqlObject('table_name','connection_name');

The function can be named anything you want it to be, as long as it is easy for you to remember. If you want to make a connection the default for that data source type, then make a call to it in the cnDefault() function for that class.

function cnDefault() {
$this->test();
}

This will allow you make the connection to test without specifying the second parameter in a child class instantiation statement.

$obj = new mySqlObject('table_name');

Custom connection types can be created by the user by creating a class for it. All connection classes implement the dbConn interface, since the cnDefault() method is a requirement.


Related

Wiki: Home

MongoDB Logo MongoDB