Overview

Namespaces

  • Rundiz
    • DataTable

Classes

  • Rundiz\DataTable\Database
  • Rundiz\DataTable\DataTable
  • Overview
  • Namespace
  • Class
 1: <?php
 2: /**
 3:  * @package Data Table
 4:  * @author Vee W.
 5:  * @license http://opensource.org/licenses/MIT MIT
 6:  */
 7: 
 8: 
 9: namespace Rundiz\DataTable;
10: 
11: /**
12:  * Database class for working with CRUD, build the query.
13:  *
14:  * @author Vee W.
15:  */
16: class Database
17: {
18: 
19: 
20:     /**
21:      * @var \PDO The PDO class object.
22:      */
23:     public $PDO;
24: 
25: 
26:     /**
27:      * Database class constructor.
28:      * 
29:      * @param array $config Available config key: [dsn], [username], [password], [options] (see more at http://php.net/manual/en/pdo.construct.php)
30:      */
31:     public function __construct(array $config = [])
32:     {
33:         if (!array_key_exists('dsn', $config)) {
34:             $config['dsn'] = '';
35:         }
36:         if (!array_key_exists('username', $config)) {
37:             $config['username'] = '';
38:         }
39:         if (!array_key_exists('password', $config)) {
40:             $config['password'] = '';
41:         }
42:         if (!array_key_exists('options', $config)) {
43:             $config['options'] = [];
44:         }
45: 
46:         try {
47:             $this->PDO = new \PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
48:             $this->PDO->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
49:             $this->PDO->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
50:         } catch (\PDOException $e) {
51:             throw new \Exception($e->getMessage());
52:         }
53:     }// __construct
54: 
55: 
56: }
57: 
API documentation generated by ApiGen