Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database {
- private $nomeTabella;
- private $conn;
- public function connettiAlDB(){
- $username = "prova"; $password = "gtgt";
- try{
- // connessione
- $conn = new PDO("mysql:host=localhost;dbname=my_tesinandroid", $username, $password);
- // abilita gestione errori tramite try ? catch (Exception)
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch(PDOException $ex){
- die("Errore connessione: ".$ex->getMessage());
- }
- }
- public function selezionaTabella($nomeTabella){
- $this->$nomeTabella = $nomeTabella;
- }
- public function scriviSulDB($sql){
- //SCRIVERE SU DB
- try {
- $stmSql = $conn->prepare($sql);
- // $stmSql ->bindParam(1, $nome);
- // $stmSql ->bindParam(2, $telefono);
- $risultato = $stmSql ->execute();
- return $risultato;
- } catch (PDOException $ex) {
- echo("Query errata".$ex->getMessage());
- }
- }
- public function leggiDalDB($sql){
- //LEGGERE DA DB
- try {
- $stmSql = $conn->prepare($sql);
- $result = $stmSql ->execute();
- return $result;
- } catch (PDOException $ex) {
- die("Query errata".$ex->getMessage());
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement