-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.php
More file actions
30 lines (25 loc) · 823 Bytes
/
db.php
File metadata and controls
30 lines (25 loc) · 823 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
<?php
class dbcon {
protected $db;
public function __construct() {
try {
$db_host = 'localhost'; // hostname
$db_name = 'ping'; // databasename
$db_user = 'root'; // username
$user_pw = ''; // password
$con = new PDO('mysql:host='.$db_host.'; dbname='.$db_name, $db_user, $user_pw);
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$con->exec("SET CHARACTER SET utf8"); // return all sql requests as UTF-8
$this->db = $con;
}
catch (PDOException $err) {
echo "harmless error message if the connection fails";
$err->getMessage() . "<br/>";
die(); // terminate connection
}
}
public function connect() {
return $this->db;
}
}
?>