-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
38 lines (26 loc) · 877 Bytes
/
db.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
<?php
define('DB_HOST','localhost');
define('DB_USER','root');
define('DB_PASS','');
define('DB_NAME','medicamentos_android');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) {
echo "Fallo al conectar con MySQL: " . mysqli_connect_error();
die();
}
$stmt = $conn->prepare("SELECT medicamentoID, nombre, comprimido, stock, precio, imagen, receta FROM medicamentos;");
$stmt->execute();
$stmt->bind_result($id, $nombre, $comprimido, $stock, $precio, $imagen, $receta);
$medicamen = array();
while($stmt->fetch()){
$temp = array();
$temp['medicamentoID'] = $id;
$temp['nombre'] = $nombre;
$temp['comprimido'] = $comprimido;
$temp['stock'] = $stock;
$temp['precio'] = $precio;
$temp['imagen'] = $imagen;
$temp['receta'] = $receta;
array_push($medicamen, $temp);
}
echo json_encode($medicamen);