-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.php
53 lines (46 loc) · 1.2 KB
/
Database.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
<?php
/**
* Created by PhpStorm.
* User: Arafeh
* Date: 5/14/2018
* Time: 5:22 PM
*/
include "models/Media.php";
class Database
{
/** @var mysqli */
static $connection;
static function getInstance()
{
if (!self::$connection) {
self::$connection = new mysqli('localhost', 'root', '', 'waves');
}
return self::$connection;
}
/**
* @param $content string
* @param $path string
* @param $lat double
* @param $lng double
* @return bool|mysqli_result
*/
static function addMedia($content, $path, $lat, $lng)
{
$sql = "INSERT INTO media (Content, MediaPath, Lat, Lng) VALUES (
'{$content}','{$path}',{$lat},{$lng}
)";
return self::getInstance()->query($sql);
}
/**
* @return array
*/
static function getMedias()
{
$sql = "SELECT * FROM media where IsDeleted = 0";
$rows = self::getInstance()->query($sql)->fetch_all(MYSQLI_ASSOC);
$medias = array_map(function ($assoc) {
return new Media($assoc['MediaId'], $assoc['Content'], $assoc['MediaPath'], $assoc['Lat'], $assoc['Lng']);
}, $rows);
return $medias;
}
}