-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.php
62 lines (45 loc) · 1.49 KB
/
model.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
<?php
function open_database_connection()
{
$link = mysqli_connect('localhost', 'root', '', 'blog_db');
return $link;
}
function close_database_connection($link)
{
mysqli_close($link);
}
function is_user( $login, $password )
{
$isuser = False ;
$link = open_database_connection();
$query= 'SELECT login FROM Users WHERE login="'.$login.'" and password="'.$password.'"';
$result = mysqli_query($link, $query );
if( mysqli_num_rows( $result) )
$isuser = True;
mysqli_free_result( $result );
close_database_connection($link);
return $isuser;
}
function get_all_posts()
{
$link = open_database_connection();
$resultall = mysqli_query($link,'SELECT id, title FROM Post');
$posts = array();
while ($row = mysqli_fetch_assoc($resultall)) {
$posts[] = $row;
}
mysqli_free_result( $resultall);
close_database_connection($link);
return $posts;
}
function get_post( $id )
{
$link = open_database_connection();
$id = intval($id);
$result = mysqli_query($link, 'SELECT * FROM Post WHERE id='.$id );
$post = mysqli_fetch_assoc($result);
mysqli_free_result( $result);
close_database_connection($link);
return $post;
}
?>