Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function __construct()
- {
- try
- {
- #array com dados do banco
- include 'database.conf.php';
- global $databases;
- $this->config = $databases['local'];
- # Recupera os dados de conexao do config
- $this->dbname = $this->config['dbname'];
- $this->host = $this->config['host'];
- $this->port = $this->config['port'];
- $this->user = $this->config['user'];
- $this->pass = $this->config['password'];
- # instancia e retorna objeto
- $this->con = @mysql_connect( "$this->host", "$this->user", "$this->pass" );
- @mysql_select_db( "$this->dbname" );
- if ( !$this->con )
- {
- throw new Exception( "Falha na conexão MySql com o banco [$this->dbname] em database.conf.php" );
- }
- else
- {
- return $this->con;
- }
- }
- catch ( Exception $e )
- {
- echo $e->getMessage();
- exit;
- }
- return $this;
- }
- <?php
- global $databases;
- $databases = array(
- 'local' => array
- (
- 'host'=>'localhost',
- 'port'=>3306,
- 'dbname'=>'ok',
- 'user'=>'root',
- 'password'=>'root'
- )
- );
Add Comment
Please, Sign In to add comment