-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathpdo.php
More file actions
31 lines (26 loc) · 979 Bytes
/
pdo.php
File metadata and controls
31 lines (26 loc) · 979 Bytes
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
<?php
namespace phpListRestapi;
defined('PHPLISTINIT') || die;
/**
* Class PDO.
*/
class PDO extends \PDO
{
public static function getConnection()
{
$dbhost = $GLOBALS['database_host'];
$dbuser = $GLOBALS['database_user'];
$dbpass = $GLOBALS['database_password'];
$dbname = $GLOBALS['database_name'];
$dbport = $GLOBALS['database_port'];
$dbsock = $GLOBALS['database_socket'];
// There is no error checking here
if (isset($dbsock) ) {
$dbh = new \PDO("mysql:dbname=$dbname;unix_socket=$dbsock;charset=UTF8;", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
} else {
$dbh = new \PDO("mysql:host=$dbhost;dbname=$dbname;port=$dbport;charset=UTF8;", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
}
$dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $dbh;
}
}