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:

extension=php_mysql.dll   
    or 
extension=php_mysql.so 

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:

<?php
    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:

<?php
    // 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:

<?php
    $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
Comment
Unity49
Reply #11 on : Sat October 27, 2018, 06:16:50
<a href="http://www.heorrecruiting.com/100-best-shoes/adidas-copa-tango-181-in-cq0132">adidas copa tango 181 in cq0132</a><a href="http://www.heorrecruiting.com/2018/nike-hyperdunk-2012-tb-team-red-white-for-sasle">nike hyperdunk 2012 tb team red white for sasle</a><a href="http://www.heorrecruiting.com/2019-updates/655206-640-nike-roshe-run-print-chilling-red-deep-royal-blue-hyper-cobalt-mens">655206 640 nike roshe run print chilling red deep royal blue hyper cobalt mens</a><a href="http://www.heorrecruiting.com/2019/brigetta-barretts-air-jordan-gold-collection">brigetta barretts air jordan gold collection</a>
[url=http://www.apluswildlifecontol-llc.com/Top_Sneakers/sale-authentic-air-jordan-6-vi-white-army-green-yellow]sale authentic air jordan 6 vi white army green yellow[/url]
new balance womens 520v3 comfort ride running shoe
Posts: 23
Comment
Snippet744
Reply #10 on : Sun November 04, 2018, 04:57:45
<a href="http://www.on-text.com/online_kicks/atmos-x-adidas-originals">atmos x adidas originals</a><a href="http://www.on-text.com/outlet/nike-air-max-270-flyknit-midnight-navy-black-white-ah8050-400-boys-running">nike air max 270 flyknit midnight navy black white ah8050 400 boys running</a><a href="http://www.on-text.com/popular-releases/supreme-x-nike-air-max-98-black-for-sale">supreme x nike air max 98 black for sale</a><a href="http://www.on-text.com/recommended/doernbecher-nike-kyrie-3">doernbecher nike kyrie 3</a>
[url=http://www.iknowmilton.com/top-kicks/new-balance-womens-520v3-comfort-ride-running-shoe]new balance womens 520v3 comfort ride running shoe[/url]
adidas adilette prima sko dam
Posts: 23
Comment
Joystick57
Reply #9 on : Tue November 27, 2018, 20:12:54
<a href="http://www.buchholzpaintnautobody.com/schoenen/nike-scarpa-bassa-uomo-air-max-axis-premium-blackmushroom">nike scarpa bassa uomo air max axis premium blackmushroom</a><a href="http://www.buchholzpaintnautobody.com/schuhe/converse-one-star-pro-cf-suede-olive-gr%c3%bcn-157869c">converse one star pro cf suede olive gr?n 157869c</a><a href="http://www.buchholzpaintnautobody.com/se/nike-epic-react-flyknit-id-damskie">nike epic react flyknit id damskie</a><a href="http://www.buchholzpaintnautobody.com/sko/nike-internationalist-dames-legergroen">nike internationalist dames legergroen</a>
[url=http://www.costarica-mls.com/sko/adidas-adilette-prima-sko-dam]adidas adilette prima sko dam[/url]
nike jordan eclipse black
Posts: 23
Comment
Verily521
Reply #8 on : Thu January 03, 2019, 16:55:47
<a href="http://www.getitgetfit.com/size/nike-air-max-1-essential-black-light-bone-white">nike air max 1 essential black light bone white</a>
[url=http://www.googoltime.com/size/nike-jordan-eclipse-black]nike jordan eclipse black[/url]
excellent nike free focus flyknit 2 blue glow ghost green white 880630 400
Posts: 23
Comment
Marit516
Reply #7 on : Sun January 06, 2019, 23:49:46
<a href="http://www.danieltraveler.com/where-to-get-cheap/puma-muse-en-pointe-womens-shoes">puma muse en pointe womens shoes</a><a href="http://www.danieltraveler.com/wholesale-searches/nike-air-max-black-blue-mens-new">nike air max black blue mens new</a><a href="http://www.danieltraveler.com/Women'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="http://www.danieltraveler.com/women/mens-nike-reax-tr-3-sl-training-shoes">mens nike reax tr 3 sl training shoes</a>
[url=http://www.gripmaps.com/Footwear/excellent-nike-free-focus-flyknit-2-blue-glow-ghost-green-white-880630-400]excellent nike free focus flyknit 2 blue glow ghost green white 880630 400[/url]
nike air force 1 black size 7
Posts: 23
Comment
Veri434
Reply #6 on : Tue January 08, 2019, 01:06:17
<a href="http://www.carpasleonltda.com/replica/nike-air-zoom-pegasus-shoes">nike air zoom pegasus shoes</a>
[url=http://www.djadc.com/shop/nike-air-force-1-black-size-7]nike air force 1 black size 7[/url]
nike roshe run slip on black volt
Posts: 23
Comment
Yap347
Reply #5 on : Thu January 17, 2019, 11:25:15
<a href="http://www.gracefullightentertainment.com/2018-released/nike-zoom-air-uptempo">nike zoom air uptempo</a><a href="http://www.gracefullightentertainment.com/2019_new_arrival/new-balance-999-made-in-us-color-spectrum-beige-with-clear-sky">new balance 999 made in us color spectrum beige with clear sky</a><a href="http://www.gracefullightentertainment.com/68-off-sale/acronym-x-nikelab-air-presto-low-all-black-shoes">acronym x nikelab air presto low all black shoes</a><a href="http://www.gracefullightentertainment.com/6pm-shoes/cheap-nike-sb-dunk-low-black-wolf-grey-dunk-shoe">cheap nike sb dunk low black wolf grey dunk shoe</a>
[url=http://www.pixyedges.com/featured/nike-roshe-run-slip-on-black-volt]nike roshe run slip on black volt[/url]
nikelab air flight 89 2018 off white nike
Posts: 23
Comment
Zygote575
Reply #4 on : Sat February 02, 2019, 03:08:28
<a href="http://www.lanetafutbolera.com/code/nike-air-jordan-2-retro-just-don-arctic-orange-ps">nike air jordan 2 retro just don arctic orange ps</a><a href="http://www.lanetafutbolera.com/coupons/green-black-nike-mens-running-shoe-air-max-fluorescence-2013">green black nike mens running shoe air max fluorescence 2013</a><a href="http://www.lanetafutbolera.com/daily-sale/adidas-tubular-invader-2-triple-white">adidas tubular invader 2 triple white</a><a href="http://www.lanetafutbolera.com/departments-sneakes/nike-air-jordan-6-retro-gatorade-green">nike air jordan 6 retro gatorade green</a>
[url=http://www.pkdakhoa.com/outlet/nikelab-air-flight-89-2018-off-white-nike]nikelab air flight 89 2018 off white nike[/url]
mens under armour fade rst e golf shoes
Posts: 23
Comment
Gerald777
Reply #3 on : Fri March 22, 2019, 02:09:27
<a href="http://www.sandelavionics.com/online/nike-zoom-lebron-st-ii-mens-shoes-black-red-excellent-quality">nike zoom lebron st ii mens shoes black red excellent quality</a><a href="http://www.sandelavionics.com/online_store/shop-cheap-air-jordan-13-barons">shop cheap air jordan 13 barons</a><a href="http://www.sandelavionics.com/outlet-brands/adidas-sambarose-black-white-gum-w">adidas sambarose black white gum w</a><a href="http://www.sandelavionics.com/outlet/adidas-adizero-adios-boost-core-black-highsnobiety">adidas adizero adios boost core black highsnobiety</a>
[url=http://www.chiczutphen.com/a_first_look/mens-under-armour-fade-rst-e-golf-shoes]mens under armour fade rst e golf shoes[/url]
zapatillas para andar mujer
Posts: 23
Comment
Veri733
Reply #2 on : Tue April 30, 2019, 02:07:52
<a href="http://www.movingonupcoaching.com/catalogue/nike-womens-dunk-sky-high-vntg-femme">nike womens dunk sky high vntg femme</a><a href="http://www.movingonupcoaching.com/cheap/scarpe-nike-air-max-bw-ultra-grey-white">scarpe nike air max bw ultra grey white</a><a href="http://www.movingonupcoaching.com/converse/reebok-print-premier-ultraknit-homme">reebok print premier ultraknit homme</a><a href="http://www.movingonupcoaching.com/cortez/chaussures-nike-air-max-1-pink-flash-femme">chaussures nike air max 1 pink flash femme</a>
[url=http://www.kneipengaenger.com/merchandise/zapatillas-para-andar-mujer]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.