Advertisement
danimaaan

conexao_banco_de_dados

Mar 13th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2.  
  3. class conexao_banco {
  4.  
  5. //Declarando os atributos
  6.  
  7.     private static $hostname;
  8.     private static $usuario;
  9.     private static $senha;
  10.     private $banco;
  11.     private $query;
  12.     private $conexao;
  13.  
  14. //    function __construct() {
  15. //        //Iniciando a conexão com o banco
  16. //        $this->open();
  17. //    }
  18.  
  19.     public function getQuery() {
  20.         return $this->query;
  21.     }
  22.  
  23.     public function getConexao() {
  24.         return $this->conexao;
  25.     }
  26.  
  27.     public function setQuery($query) {
  28.         $this->query = $query;
  29.     }
  30.  
  31.     public function open() {
  32.         $this->conexao = mysql_connect("localhost", "root", "123456");
  33.  
  34.         if (!$this->conexao) {
  35.             echo "Erro na conexão com o banco de dados!";
  36.         } elseif (!$this->banco) {
  37.             echo "Banco de dados inexistente";
  38.         } else {
  39.             $this->banco = mysql_select_db("teste");
  40.         }
  41.     }
  42.  
  43.     public function close() {
  44.         mysql_close($this->conexao);
  45.     }
  46.  
  47.     public function query($sql) {
  48.         $this->query = mysql_query($sql);
  49.         return $this->query;
  50.     }
  51.  
  52.     // retorna quantas linhas aquela query resultou
  53.     public function total_Linhas($sql) {
  54.         return mysql_num_rows($this->query);
  55.     }
  56.  
  57. }
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement