-
Notifications
You must be signed in to change notification settings - Fork 2
/
Database.php
42 lines (39 loc) · 1.08 KB
/
Database.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
<?php
class Database {
/**
* @return null|PDO
*
* Veritabanı bağlantısı
*/
private function connect()
{
$db = null;
if ($db === null) {
try
{
$dsn = 'mysql:host='.DB_SERVER.';dbname='.DB_NAME.';port='.DB_PORT.';charset=utf8';
$db = new PDO($dsn, DB_USERNAME, DB_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
echo $e->getMessage();
}
}
return $db;
}
public function result($query_string, $params = array()) {
try {
$query = $this->connect()->prepare($query_string);
if(!empty($params)) {
foreach ($params as $key => $value) {
$query->bindParam(':'.$key, $value);
}
}
$query->execute();
return $query->fetchAll(PDO::FETCH_OBJ);
} catch(PDOException $e) {
return $e->getMessage();
}
}
}