-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.php
68 lines (60 loc) · 2.04 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
60
61
62
63
64
65
66
67
68
<?php
class database
{
private $con;
private $dbhost="localhost";
private $dbuser="root";
private $dbpass="";
private $dbname="prueba_poo";
function __construct(){
$this->connect_db();
}
public function connect_db(){
$this->con = mysqli_connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
if(mysqli_connect_error()){
die("Conexión a la base de datos falló " . mysqli_connect_error() . mysqli_connect_errno());
}
}
public function sanitize($var){
$return = mysqli_real_escape_string($this->con, $var);
return $return;
}
public function create($nombres,$apellidos,$telefono,$direccion,$correo_electronico){
$sql = "INSERT INTO `clientes` (nombres, apellidos, telefono, direccion, correo_electronico) VALUES ('$nombres', '$apellidos', '$telefono', '$direccion', '$correo_electronico')";
$res = mysqli_query($this->con, $sql);
if($res){
return true;
}else{
return false;
}
}
public function read(){
$sql = "SELECT * FROM clientes";
$res = mysqli_query($this->con, $sql);
return $res;
}
public function single_record($id){
$sql = "SELECT * FROM clientes where id='$id'";
$res = mysqli_query($this->con, $sql);
$return = mysqli_fetch_object($res );
return $return ;
}
public function update($nombres,$apellidos,$telefono,$direccion,$correo_electronico, $id){
$sql = "UPDATE clientes SET nombres='$nombres', apellidos='$apellidos', telefono='$telefono', direccion='$direccion', correo_electronico='$correo_electronico' WHERE id=$id";
$res = mysqli_query($this->con, $sql);
if($res){
return true;
}else{
return false;
}
}
public function delete($id){
$sql = "DELETE FROM clientes WHERE id=$id";
$res = mysqli_query($this->con, $sql);
if($res){
return true;
}else{
return false;
}
}
}