-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconexao.php
32 lines (23 loc) · 840 Bytes
/
conexao.php
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
<?php
function conexaoDB(){
try {
$configdb = include "config.php";
if (!isset($configdb['db'])){
throw new \InvalidArgumentException("Paramertos de banco de dados indefinidos.");
}
$host = (isset($configdb['db']['host'])) ? $configdb['db']['host'] : null;
$dbname = (isset($configdb['db']['dbname'])) ? $configdb['db']['dbname'] : null;
$user = (isset($configdb['db']['user'])) ? $configdb['db']['user'] : null;
$password = (isset($configdb['db']['password']))? $configdb['db']['password']: null;
return new \PDO("mysql:host={$host};dbname={$dbname}", $user, $password);
}
catch (\PDOException $e){
echo $e->getMessage() . "\n";
echo $e->getTraceAsString() . "\n";
}
}
// $teste = include "config.php";
// print_r($teste);
// $conn = conexaoDB();
// print_r($conn);
?>