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 .

sale authentic air jordan 6 vi white army green yellow
Posts: 23
Reply #11 on : Sat October 27, 2018, 06:16:50
<a href="">adidas copa tango 181 in cq0132</a><a href="">nike hyperdunk 2012 tb team red white for sasle</a><a href="">655206 640 nike roshe run print chilling red deep royal blue hyper cobalt mens</a><a href="">brigetta barretts air jordan gold collection</a>
[url=]sale authentic air jordan 6 vi white army green yellow[/url]
new balance womens 520v3 comfort ride running shoe
Posts: 23
Reply #10 on : Sun November 04, 2018, 04:57:45
<a href="">atmos x adidas originals</a><a href="">nike air max 270 flyknit midnight navy black white ah8050 400 boys running</a><a href="">supreme x nike air max 98 black for sale</a><a href="">doernbecher nike kyrie 3</a>
[url=]new balance womens 520v3 comfort ride running shoe[/url]
adidas adilette prima sko dam
Posts: 23
Reply #9 on : Tue November 27, 2018, 20:12:54
<a href="">nike scarpa bassa uomo air max axis premium blackmushroom</a><a href="">converse one star pro cf suede olive gr?n 157869c</a><a href="">nike epic react flyknit id damskie</a><a href="">nike internationalist dames legergroen</a>
[url=]adidas adilette prima sko dam[/url]
nike jordan eclipse black
Posts: 23
Reply #8 on : Thu January 03, 2019, 16:55:47
<a href="">nike air max 1 essential black light bone white</a>
[url=]nike jordan eclipse black[/url]
excellent nike free focus flyknit 2 blue glow ghost green white 880630 400
Posts: 23
Reply #7 on : Sun January 06, 2019, 23:49:46
<a href="">puma muse en pointe womens shoes</a><a href="">nike air max black blue mens new</a><a href="'s_Shoes/black-trainer-nike-air-max-95-premium-rose-salmon-sneakerdiscount">black trainer nike air max 95 premium rose salmon sneakerdiscount</a><a href="">mens nike reax tr 3 sl training shoes</a>
[url=]excellent nike free focus flyknit 2 blue glow ghost green white 880630 400[/url]
nike air force 1 black size 7
Posts: 23
Reply #6 on : Tue January 08, 2019, 01:06:17
<a href="">nike air zoom pegasus shoes</a>
[url=]nike air force 1 black size 7[/url]
nike roshe run slip on black volt
Posts: 23
Reply #5 on : Thu January 17, 2019, 11:25:15
<a href="">nike zoom air uptempo</a><a href="">new balance 999 made in us color spectrum beige with clear sky</a><a href="">acronym x nikelab air presto low all black shoes</a><a href="">cheap nike sb dunk low black wolf grey dunk shoe</a>
[url=]nike roshe run slip on black volt[/url]
nikelab air flight 89 2018 off white nike
Posts: 23
Reply #4 on : Sat February 02, 2019, 03:08:28
<a href="">nike air jordan 2 retro just don arctic orange ps</a><a href="">green black nike mens running shoe air max fluorescence 2013</a><a href="">adidas tubular invader 2 triple white</a><a href="">nike air jordan 6 retro gatorade green</a>
[url=]nikelab air flight 89 2018 off white nike[/url]
mens under armour fade rst e golf shoes
Posts: 23
Reply #3 on : Fri March 22, 2019, 02:09:27
<a href="">nike zoom lebron st ii mens shoes black red excellent quality</a><a href="">shop cheap air jordan 13 barons</a><a href="">adidas sambarose black white gum w</a><a href="">adidas adizero adios boost core black highsnobiety</a>
[url=]mens under armour fade rst e golf shoes[/url]
zapatillas para andar mujer
Posts: 23
Reply #2 on : Tue April 30, 2019, 02:07:52
<a href="">nike womens dunk sky high vntg femme</a><a href="">scarpe nike air max bw ultra grey white</a><a href="">reebok print premier ultraknit homme</a><a href="">chaussures nike air max 1 pink flash femme</a>
[url=]zapatillas para andar mujer[/url]
First | Previous | Showing comments 11 to 20 of 21 | Next | Last

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.