-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbIndex.php
43 lines (39 loc) · 861 Bytes
/
dbIndex.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
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
class Database {
// dummy values, switch with real ones
protected static $name = 'mysql:dbname=dev_cms;host=127.0.0.1';
protected static $user = 'root';
protected static $password = '1234';
public function __construct() {
$this->db_name = self::$name;
$this->db_user = self::$user;
$this->db_password = self::$password;
}
public function connect() {
try {
$dbh = new PDO($this->db_name, $this->db_user, $this->db_password);
return $dbh;
}
catch (PDOException $e) {
echo 'Connection failed '. $e->getMessage();
die();
}
}
public function getRow()
{
try
{
$dbh = $this->connect();
foreach($dbh->query('SELECT * from workers') as $row) {
print_r($row);
}
}
catch(PDOException $e)
{
echo 'Error '. $e->getMessage();
die();
}
}
}