-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.pdotool.php
52 lines (47 loc) · 919 Bytes
/
class.pdotool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Tool for Toolbox
* @package Toolbox
*/
require_once 'class.builder.php';
/**
* Create a PDO link to a database
*
* @package Toolbox
* @author Sergi Juanola
* @copyright Sergi Juanola 2012-2013
* @link Builder
*/
class Pdotool extends Builder {
/**
* Default properties.
*/
public static $default = array(
'host' => '',
'user' => '',
'pass' => '',
'dbname' => '',
'dsn' => null,
'charset' => 'utf8',
'driver' => 'mysql'
);
/**
* Building method
* @param array $config The config array
* @link Builder::build()
*/
public static function build($config = array()) {
$self = new self($config);
if(empty($self->dsn))
{
switch ($self->driver) {
default:
case 'mysql':
$self->dsn = 'mysql:host='.$self->host.';dbname='.$self->dbname.';charset='.$self->charset;
break;
}
}
$pdo = new PDO($self->dsn, $self->user, $self->pass);
return $pdo;
}
}