forked from mibe/FeedWriter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconexao.php
More file actions
executable file
·66 lines (52 loc) · 2 KB
/
conexao.php
File metadata and controls
executable file
·66 lines (52 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class Conexao {
//Instância de conexão PDO
private static $instance = null;
//Tipo de banco de dados
private static $dbType = "mysql";
/*--------------------------------------------------------------------*/
/* Parâmetros de configuração do banco de dados */
/*--------------------------------------------------------------------*/
private static $host = "localhost";//SERVIDOR DO BANCO DE DADOS
private static $user = "root"; //USUARIO DE CONEXÃO DO BANCO DE DADOS
private static $senha = ""; //SENHA DE CONEXÃO DO BANCO DE DADOS
private static $banco = "feed";//NOME DO BANCO DE DADOS
/*--------------------------------------------------------------------*/
//Define se a conexão deve ser persistente
protected static $persistent = false;
/*--------------------------------------------------------------------*/
/* Lista de Tabelas do Banco */
/*--------------------------------------------------------------------*/
private static $tabelas = array (
'TB_NOTICIAS' => 'noticias'
);
/*--------------------------------------------------------------------*/
//Retorna a instância de conexão ao banco de dados
public static function getInstance() {
if(self::$persistent != FALSE) {
self::$persistent = TRUE;
}
if (!isset(self::$instance)) {
try {
self::$instance = new PDO(self::$dbType.':host='.self::$host.';dbname='.self::$banco
, self::$user
, self::$senha
, array(PDO::ATTR_PERSISTENT => self::$persistent));
} catch (PDOException $ex) {
exit("Erro ao estabelecer a conexão com o banco de dados". $ex->getMessage());
}
}
return self::$instance;
}
//Função pra fechar a conexão com o banco de dados
public static function close() {
if(self::$instance != null) {
self::$instance = null;
}
}
//Recebe uma chave e retorna a tabela correspondente a essa chave
public static function getTabela($chave) {
return self::$tabelas[$chave];
}
}
?>