Advertisement
heyfranks

conexion class

May 6th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2. class conexion {
  3.    
  4.     protected $servidor;
  5.     protected $usuario;
  6.     protected $password;
  7.     protected $database;
  8.     public $mysqli;
  9.    
  10.     public function __construct() {
  11.         $this->servidor = 'localhost';
  12.         $this->usuario = 'root';
  13.         $this->password = '';
  14.         $this->database = 'db';
  15.     }
  16.  
  17.     public function conectar() {
  18.        
  19.         $this->mysqli = new mysqli($this->servidor, $this->usuario, $this->password, $this->database);
  20.         if (mysqli_connect_errno()) {
  21.             echo 'Error en base de datos: '. mysqli_connect_error();
  22.             exit();
  23.         }
  24.        
  25.         $this->mysqli->query("SET NAMES 'utf8'");
  26.         $this->mysqli->query("SET CHARACTER SET utf8");
  27.     }
  28.  
  29.     public function desconectar() {
  30.         mysqli_close($this->mysqli);
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement