Last active
December 13, 2021 13:20
-
-
Save rcervera/3c7715a5172afe0254b08071a4c5ed5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Model { | |
protected $bd; | |
protected $usuari="root"; | |
protected $password="usuari"; | |
protected $taula; | |
protected $database ="supersBD"; | |
protected $host = "localhost"; | |
function __construct() { | |
try { | |
$this->bd = new PDO('mysql:host='.$this->host.';dbname='.$this->database, | |
$this->usuari, $this->password, array( | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
PDO::ATTR_EMULATE_PREPARES => false | |
)); | |
} catch (PDOException $e) { | |
echo "Error: No s'ha pogut connectar amb la base de dades"; | |
die(); | |
} | |
} | |
// Obtenir tots els registres d'una taula | |
public function getAll() { | |
$sql = "select * from ".$this->taula; | |
$ordre = $this->bd->prepare($sql); | |
$ordre->execute(); | |
$res = $ordre->fetchAll(PDO::FETCH_ASSOC); | |
return $res; | |
} | |
// Implementa un mètode per obtenir un registre determinat d'una taula segons un valor passat per paràmetre | |
// Condició necessària: Totes les taules tindran una única clau primària amb nom id | |
// exemple: obtenir l'usuari amb id = 1 | |
// exemple: obtenir el producte amb id = 120 | |
public function get($codi) { | |
} | |
// Implementa un mètode per esborrar un registre determinat d'una taula segons un valor passat per paràmetre | |
// Condició necessària: Totes les taules tindran una única clau primària amb nom id | |
// exemple: esborrar l'usuari amb id = 1 | |
// exemple: esborrar el producte amb id = 120 | |
public function delete($codi) { | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment