-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnector-FMD.php
executable file
·85 lines (64 loc) · 2.1 KB
/
connector-FMD.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
<?php
// Database wrapper
class Db {
// The database connection
protected static $connection;
// connect to the database
// @return bool false on failure / mysqli MySQLi object instance on success
public function connect() {
// Try and connect to the db
if ( !isset (self::$connection) ) {
self::$connection = new mysqli_connect('localhost', 'root', '', teamtian);
//Load configuration as an array. Use the actual location of your
// configuration file
// $config = parse_ini_file('../config.ini');
// self::$connection = new mysqli_connect('rockit.ccyd2ljjwzet.us-east-1.rds.amazonaws.com',
// $config['username'],
// $config['password'],
// $config['dbname'] );
}
// if the connection was not successful, handle error
if (self::$connection === false) {
echo "No connection ... *sigh";
return false;
}
return self::$connection;
}
// Query the DB
// @param $query the query string
// @return mixed the result of the mysqli::query() function
public function query($query) {
// connect to the db
$connection = $this -> connect();
// query db
$result = $connection -> query($query);
return $result;
}
// Fetch Rows from the db (SELECT query)
// @param $query the query string
// @return bool false on failure / array Database rows on success
public function select($query) {
$rows = array();
$result = $this -> query($query);
if($result === false) {
return false;
}
while ($row = $result -> fetch_assoc() ) {
$rows[] = $row;
}
return $rows;
}
// Fetch the last error from the db
// @return string Database error message
public function error() {
$connection = $this -> connect();
return $connection -> error;
}
// quote and escape value for use in a database query
// @param string $value The value to be quoted and escaped
// @return string The quoted and escaped string
public function quote($value) {
$connection = $this -> connect();
return "'" . $connection -> cubrid_real_escape_string($value) . "'";
}
}