
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 .
Posts: 23

Reply #10 on : Sun November 04, 2018, 04:57:45
Posts: 23

Reply #9 on : Tue November 27, 2018, 20:12:54
Posts: 23

Reply #8 on : Thu January 03, 2019, 16:55:47
Posts: 23

Reply #7 on : Sun January 06, 2019, 23:49:46
Posts: 23

Reply #6 on : Tue January 08, 2019, 01:06:17
Posts: 23

Reply #5 on : Thu January 17, 2019, 11:25:15
Posts: 23

Reply #4 on : Sat February 02, 2019, 03:08:28
Posts: 23

Reply #3 on : Fri March 22, 2019, 02:09:27
Posts: 23

Reply #2 on : Tue April 30, 2019, 02:07:52
Posts: 23
Reply #11 on : Sat October 27, 2018, 06:16:50