-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.php
71 lines (58 loc) · 1.54 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
60
61
62
63
64
65
66
67
68
69
70
71
<?php
//Parameters
define("DB_NAME","securite");
define("DB_SERVER","localhost");
define("DB_USERNAME","root");
define("DB_PASSWORD","");
global $bdd;
$bdd = new PDO( 'mysql:host=' . DB_SERVER . ';dbname=' . DB_NAME, DB_USERNAME , DB_PASSWORD, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) );
function getPosts($sWhere = ""){
global $bdd;
$sql = "select * from posts ".$sWhere;
$result = $bdd -> query($sql);
$rows = array();
foreach ( $result as $row){
$rows[]= $row;
}
return $rows;
}
function getComments($sWhere = ""){
global $bdd;
$sql = "select * from comments ".$sWhere;
$result = $bdd -> query($sql);
$rows = array();
foreach ( $result as $row){
$rows[]= $row;
}
return $rows;
}
function getUser($sLogin = "", $sPassword = ""){
global $bdd;
$sql = "select * from users where email = '".$sLogin."' and password = '".$sPassword."'";
$result = $bdd -> query($sql);
$row = null;
foreach ( $result as $row){
}
return $row;
}
function getUsers($sWhere = ""){
global $bdd;
$sql = "select * from users ".$sWhere;
$result = $bdd -> query($sql);
$rows = array();
foreach ( $result as $row){
$rows[]= $row;
}
return $rows;
}
function addComment($sEmail = "", $sContent = "", $sPostId = 0){
global $bdd;
$sql = "insert into comments (email,post_id,content) VALUES ('".$sEmail."',".$sPostId.",'".$sContent."')";
$result = $bdd -> query($sql);
}
function addPost($sTitle = "", $sContent = ""){
global $bdd;
$sql = "insert into posts (title,content) VALUES ('".$sTitle."','".$sContent."')";
$result = $bdd -> query($sql);
}
?>