Advertisement
Guest User

Untitled

a guest
May 29th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. Class DB_Connect{
  4.    
  5.    protected $db;
  6.    
  7.    public function __construct($host="localhost", $user="root", $password="", $db="test_1")
  8.    {
  9.        $this->db = new PDO("mysql:host={$host};dbname={$db}", $user,$password);
  10.  
  11.    }
  12.    
  13.    public function getInstance(){
  14.        return $this->db;
  15.    }
  16.    
  17. }
  18.  
  19.  
  20. Class Libri extends DB_Connect{
  21.        
  22.   public function __construct(){
  23.      
  24.       parent::__construct();
  25.  
  26.   }
  27.  
  28.    public function scrivi(){
  29.        
  30.        try{
  31.        
  32.        $sql=  "UPDATE `tbl_product` "
  33.             ."  SET `name` = 'Alex', "
  34.             ." `codice` = '332' "
  35.             . " WHERE `tbl_product`.`id_product` = 3 ";
  36.    
  37.         $sth = $this->db->prepare($sql);
  38.  
  39.         return $sth->execute();
  40.        
  41.        }Catch(\PDOExeption $e){
  42.            
  43.            return false;
  44.        }
  45.     }
  46. }
  47.  
  48. $libri = new Libri();
  49. // scrivo
  50. $test= $libri->scrivi();
  51. // è andato tutto bene ?
  52. if($test){
  53.     // qui tutto ok
  54. }else{
  55.     // qui si è verificato un errore  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement