How to Connect to a Database

Even though you don't need a database for some web applications, there are times when you just can't do without it. This tutorial will show you how to use Raxan to connect to a database server.

Before you can establish a connection to a database there are a few thing that you will need to do.

Load correct PDO drivers

The first thing to do is to make sure you have the correct PHP PDO driver loaded. To do this you will need to include the name of the PDO driver inside your php.ini file. For example:


There are several drivers available from the PHP website. If you're connecting to Microsft SQL server from a Windows box, then I would recommend that you download the SQL Server drivers for PHP.

Setting up a connection

Once the PDO driver is loaded you're ready to establish a connect ion. From within your application you can call the Raxan::connect() method by passing the dsn, user name, password and (optional) attributes as shown below:

    protected function _init() {
        $uid = 'user';
        $pwd = 'password';
        $dsn = 'mysql: host=localhost; dbname=orders';
        $db = Raxan::connect($dsn,$uid,$pwd);
        $this->db = $db;

The above will create a connection to the database that can be used to retrieve and update records.

Using a Database configuration file

In most cases you might want to centrally manage your database connections from a single file source. To do this you will need to create a configuration file and specify the dsn, username, etc:

    // default database
    $config['db.default'] = array(
        'dsn' => 'mysql: host=localhost; dbname=contacts',
        'user' => 'user',
        'password' => 'password',
        'attribs' =>  array()

    // another database
    $config['db.mydatabase'] = array(
        'dsn' => 'mysql: host=localhost; dbname=inventory',
        'user' => 'user',
        'password' => 'password',
        'attribs' =>  array()


Notice that the database configurations are prefixed with 'db.' To use the above configuration you simple call Raxan::connect() as show below:

    $db = Raxan::connect('default');     // connect to default database
    $db2 = Raxan::connect('mydatabase');    // connect to another database

For more information please see User Guide - Database connection .

reebok crossfit nano 7 0 b vitamin c yellow black lead w schuhe
Posts: 23
Reply #1 on : Tue May 21, 2019, 13:13:16
<a href="">basket chaussures adidas eqt support adv w</a><a href="">adidas adipower howard home white royal blue sz 9</a><a href="">adidas ultraboost st m chaussures de running homme core blackftwr white</a><a href="">nike af 1 low flower tweed hombre</a>
[url=]reebok crossfit nano 7 0 b vitamin c yellow black lead w schuhe[/url]
First | Previous | Showing comments 21 to 21 of 21

Leave a Comment

Required fields are marked with *.
If you have trouble reading the code, click on the code itself to generate a new random code.