Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="es">
- <head>
- <meta charset="utf-8">
- <title>Raspberry Pi desde cero</title>
- </head>
- <body>
- <h1>Prueba de Apache, PHP y MariaDB</h1>
- <div>
- <h2>Lista de la compra</h2>
- <table>
- <tr>
- <th>ID</th>
- <th>Nombre</th>
- <th>Cantidad</th>
- </tr>
- <?php
- $db = new Database();
- $result = $db->query("SELECT id, name, quantity FROM products");
- while($row = $result->fetch_array()){
- echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
- }
- // Liberar los resultados
- $result->free();
- // Cerrar conexión
- $db->close();
- ?>
- </table>
- </div>
- </body>
- </html>
- <?php
- class Database{
- // Dirección o IP de la base de datos
- private $host = "localhost";
- // Puerto de la base de datos
- private $port = "3306";
- // Usuario y contraseña de la base de datos
- private $user = "pi";
- private $password = "superpass"; // Nunca la subáis en un commit o en un ejemplo
- // Nombre de la base de datos
- private $bbddName ="rpi";
- // Nombre de la tabla
- private $table = "list";
- public function __construct() {
- $this->connect();
- }
- private function connect(){
- $this->mysqli = new mysqli($this->host, $this->user, $this->password, $this->bbddName);
- return $this->mysqli;
- }
- public function query($sql){
- $result = $this->mysqli->query($sql);
- return $result;
- }
- public function close(){
- $this->close();
- }
- }
- ?>
Add Comment
Please, Sign In to add comment