-
Notifications
You must be signed in to change notification settings - Fork 8
/
functions.php
48 lines (39 loc) · 1.09 KB
/
functions.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
<?php
// generate a random integer for the main page
function gen_uid($l=9){
return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyz"), 0, $l);
}
function addText(){
$request = Slim::getInstance()->request();
$text = json_decode($request->getBody());
$sql = "INSERT INTO textpad ()";
}
/* Generic CRUD functions */
class Database
{
private static $cont = null;
public function __construct() {
die('Init function is not allowed');
}
public static function connect()
{
global $dbName, $dbHost, $dbUsername, $dbUserPassword;
// One connection through whole application
if ( null == self::$cont )
{
try
{
self::$cont = new PDO( "mysql:host=".$dbHost.";"."dbname=".$dbName, $dbUsername, $dbUserPassword);
}
catch(PDOException $e)
{
die($e->getMessage());
}
}
return self::$cont;
}
public static function disconnect()
{
self::$cont = null;
}
}