-
Notifications
You must be signed in to change notification settings - Fork 0
/
Conexion.php
40 lines (32 loc) · 918 Bytes
/
Conexion.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
<?php
class Conexion {
private $_user = "root";
private $_pass = "";
private $_nombreBase = "bibloteca";
private $_direccion = "localhost";
private $_conex;
public function __construct() {
$this->_conex = @new mysqli($this->_direccion, $this->_user, $this->_pass, $this->_nombreBase);
$this->_conex->query("set names 'utf8'");
if (mysqli_connect_errno()) {
throw new RuntimeException('Error de conexión');exit;
}
}
public function __destruct() {
$this->_conex->close();
}
public function query($sql) {
return $this->datosColeccion($this->_conex->query($sql));
}
public function execute($sql) {
$this->_conex->query($sql);
}
public function datosColeccion($data) {
$datos = array();
while ($fila = mysqli_fetch_assoc($data)) {
array_push($datos, $fila);
}
return $datos;
}
}
?>