-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.php
More file actions
82 lines (64 loc) · 2.1 KB
/
Copy pathconfig.php
File metadata and controls
82 lines (64 loc) · 2.1 KB
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
<?php
/**
* @link https://pipiscrew.com
* @copyright Copyright (c) 2016 PipisCrew
*/
function connect_mysql() {
$mysql_hostname = "localhost";
$mysql_user = "";
$mysql_password = "";
$mysql_database = "test";
$dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_database", $mysql_user, $mysql_password,
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
));
return $dbh;
}
function connect() {
//if doesnt exist, will created.
$dbh = new PDO('sqlite:dbase.db');
//$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
//check if table has records, if not create table
$d = getScalar($dbh, "select count(*) from users",null);
if ($d==0)
{
executeSQL($dbh, "CREATE TABLE [users] (user_id INTEGER PRIMARY KEY, user_mail TEXT, user_password TEXT, user_level INTEGER)", null);
executeSQL($dbh, "CREATE TABLE [day_offs] (day_off_id INTEGER PRIMARY KEY, day_off_type INTEGER, user_id INTEGER, date_occur TEXT, comment TEXT)", null);
executeSQL($dbh, "your other tables here?",null);
//read&write only server (user cant download the dbase)
chmod("dbase.db", 0600);
}
//check if table has records, if not create table
return $dbh;
}
function getScalar($db, $sql, $params) {
if ($stmt = $db -> prepare($sql)) {
$stmt->execute($params);
return $stmt->fetchColumn();
} else
return 0;
}
function getRow($db, $sql, $params) {
if ($stmt = $db -> prepare($sql)) {
$stmt->execute($params);
return $stmt->fetch();
} else
return 0;
}
function getSet($db, $sql, $params) {
if ($stmt = $db -> prepare($sql)) {
$stmt->execute($params);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
// return $stmt->fetchAll();
} else
return 0;
}
function executeSQL($db, $sql, $params) {
if ($stmt = $db -> prepare($sql)) {
$stmt->execute($params);
return $stmt->rowCount();
} else
return false;
}
?>