-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataBase.php
More file actions
executable file
·44 lines (32 loc) · 1.04 KB
/
dataBase.php
File metadata and controls
executable file
·44 lines (32 loc) · 1.04 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
<?php
function insertListingFromObject($obj){
$string = "INSERT INTO stations_listings (`id`,`station_id`,`commodity_id`,`supply`,`buy_price`,`sell_price`,`demand`,`collected_at`) VALUES('";
foreach($obj as $value){
$string.=$value."','";
}
$string = substr($string, 0, -2);
$string.=")";
dao::query($string);
// echo $string;
// echo "<br>";
}
class dao {
private static $connection = false;
public static function connect() {
if(self::$connection) return true;
self::$connection = new mysqli("localhost","root","","eddb");
if (self::$connection->connect_error) {
die('Connect Error (' . self::$connection->connect_errno . ') '
. self::$connection->connect_error);
}
return true;
}
public static function query($query) {
if(!self::$connection) self::connect();
$result = self::$connection->query($query);
return $result;
}
}
dao::query('some kind of SQL query');
dao::query('another SQL query');
?>