-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.php
59 lines (38 loc) · 1.09 KB
/
config.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
53
54
55
56
57
58
59
<?php
class Posts{
public $title,$message,$PDO;
public function __construct(){
try {
$this->PDO = new PDO("mysql:host=127.0.0.1;dbname=blog", 'root', '');
$this->PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Something went wrong ' . $e->getMessage();
}
}
public function save($input){
try {
$stmt = $this->PDO->prepare("INSERT INTO posts(title,message,posted) VALUES (?,?,NOW())");
$stmt->execute($input);
} catch (PDOException $e) {
echo 'Something went wrong ' . $e->getMessage();
}
}
public static function print_object($array){
if(is_object($array) || is_array($array)){
echo '<pre>';
print_r($array);
echo '</pre>';
}
else echo 'This is not an object!';
}
public function Fetch(){
$stmt = $this->PDO->prepare('SELECT * FROM posts');
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_OBJ);
}
public function FetchOne($id){
$stmt = $this->PDO->prepare("SELECT * FROM posts WHERE id = $id");
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_OBJ);
}
}