-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniversal.php
44 lines (37 loc) · 1.22 KB
/
Universal.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
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Connect to a database using PHP PDO.
*/
class Universal
{
// Database Mysql
/*private static $database = "mysql:";
private static $host = ""; //insira o host exemplo: localhost:8080.
private static $dbname = ""; // insira o nome do banco.
private static $user = "enter username if any"; // insira o nome de usuário se houver.
private static $pass = ""; // insira a senha(password) se houver.
private static $dsn;*/
//Database Sqlite
private static $database = "sqlite:";
private static $host = "database.db";
private static $dbname = "";
private static $user = null;
private static $pass = null;
private static $dsn;
/**
* Do Connection.
*
* @return \PDO
*/
public static function doConnection()
{
self::$dsn = self::$database.self::$host.self::$dbname;
try{
$conn = new \PDO(self::$dsn, self::$user, self::$pass, array(\PDO::ATTR_PERSISTENT => true));
echo "<script>console.log('Connection successful!')</script>";
return $conn;
} catch(\PDOException $e){
exit("Connection failed error: ".$e->getMessage()."<br/>");
}
}
}