Guest User

Untitled

a guest
Mar 28th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. public function __construct()
  2. {
  3. try
  4. {
  5. #array com dados do banco
  6. include 'database.conf.php';
  7. global $databases;
  8. $this->config = $databases['local'];
  9. # Recupera os dados de conexao do config
  10. $this->dbname = $this->config['dbname'];
  11. $this->host = $this->config['host'];
  12. $this->port = $this->config['port'];
  13. $this->user = $this->config['user'];
  14. $this->pass = $this->config['password'];
  15. # instancia e retorna objeto
  16. $this->con = @mysql_connect( "$this->host", "$this->user", "$this->pass" );
  17. @mysql_select_db( "$this->dbname" );
  18. if ( !$this->con )
  19. {
  20. throw new Exception( "Falha na conexão MySql com o banco [$this->dbname] em database.conf.php" );
  21. }
  22. else
  23. {
  24. return $this->con;
  25. }
  26. }
  27. catch ( Exception $e )
  28. {
  29. echo $e->getMessage();
  30. exit;
  31. }
  32. return $this;
  33. }
  34.  
  35. <?php
  36. global $databases;
  37. $databases = array(
  38. 'local' => array
  39. (
  40. 'host'=>'localhost',
  41. 'port'=>3306,
  42. 'dbname'=>'ok',
  43. 'user'=>'root',
  44. 'password'=>'root'
  45. )
  46. );
Add Comment
Please, Sign In to add comment