-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.php
59 lines (49 loc) · 1.72 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
54
55
56
57
58
59
<?php
class Database {
public $link;
public function __construct() {
$this->link = mysqli_connect("localhost", "root", "root", "Biometria_CIGS");
if (!$this->link) {
echo '<script>window.alert(\'Erro ao conectar com o banco de dados. Contacte o administrador do sistema.\')</script>';
}
mysqli_set_charset($this->link, "utf8");
}
public function query($sql) {
$sql = str_replace("''", "NULL", $sql);
if (mysqli_query($this->link, $sql)) {
echo '<script>window.alert(\'Operação concluída com sucesso!\')</script>';
return true;
} else {
echo '<script>window.alert(\'Erro na operação\')</script>';
return false;
}
}
public function select($table, $filtro) {
if ($filtro != '') {
$sql = "select * from $table;";
} else {
$sql = "select * from $table where $filtro;";
}
$result = mysqli_query($this->link, $sql);
if ($result) {
$row = mysqli_fetch_assoc($result);
return $row;
} else {
echo "Erro em: " . $sql;
}
}
public function nextId() {
$sql = "select max(cod) as cod from titular;";
$result = mysqli_query($sql);
$row = mysqli_fetch_assoc($result);
$nextId = $row['cod'];
return $nextId;
}
public function uploadPhoto($input1, $input2) {
$target_dir = '/var/www/html/ccfexBeta/fotos/';
$target_file = $target_dir . basename($input1);
move_uploaded_file($input2, $targe_file);
echo "<script>console.log('" . print_r($FILES) . "')</script>";
}
}
?>