-
Notifications
You must be signed in to change notification settings - Fork 3
/
db_fns.php
100 lines (75 loc) · 1.86 KB
/
db_fns.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
function db_connect() {
$connection = new mysqli(MYSQL_HOSTNAME, USERNAME, PASSWORD, DATABASE);
if (!$connection)
{
echo 'baglanamadi';
mysql_error();
}
if (!$connection->select_db(DATABASE))
{
echo 'database bulunamadi';
mysql_error();
}
$connection->query("SET NAMES UTF8");
return $connection;
}
function db_result_to_array($result)
{
$res_array = array();
for ($count = 0; $row = mysqli_fetch_assoc($result); $count++)
{
$res_array[$count] = $row;
}
return $res_array;
}
function insert_video($video_id){
$conn = db_connect();
$query = "INSERT into video SET id = '$video_id'";
$result = $conn->query($query);
if(!$result){
echo 'Dünyayý ele geçirmeye falan mý çalýþýyorsun?';
echo $conn->error;
}else{
return $conn->insert_id;
}
$conn->close();
}
function is_video_inserted($video_id){
$conn = db_connect();
$query = "SELECT id FROM video WHERE id = '$video_id'";
$result = $conn->query($query);
$result = $result->fetch_array();
if($result)
{
return $result;
}
else
{
return false;
}
if(mysqli_ping($conn))
{
$conn->close();
}
}
function insert_channel($credentials){
$conn = db_connect();
$query = "INSERT into channel SET credentials = '$credentials'";
$result = $conn->query($query);
if(!$result){
echo 'Dünyayý ele geçirmeye falan mý çalýþýyorsun?';
echo $conn->error;
}else{
return $conn->insert_id;
}
$conn->close();
}
function all_channels(){
$conn = db_connect();
$query = "SELECT * FROM channel WHERE is_active=1";
$result = $conn->query($query);
$result = db_result_to_array($result);
return $result;
}
?>