forked from jayjayswal/ca-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectionClass.php
executable file
·68 lines (60 loc) · 1.6 KB
/
ConnectionClass.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
function myException($exception)
{
echo "<b>Exception:</b> " , $exception->getMessage();
}
set_exception_handler('myException');
error_reporting(0); // don't show any warnings
class getConnection
{
private static $host="localhost";
private static $username="iewoin_msubca";
private static $pass="jayswal@1";
private static $db_database = 'iewoin_bcasite';
public static function connectToDatabase()
{
try
{
$con=mysqli_connect(self::$host,self::$username,self::$pass);
if(!$con)
{
throw new Exception("Cannot connect to the database");
}
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
return $con;
}
public static function selectDatabase($con)
{
try
{
mysqli_select_db($con,self::$db_database);
if(mysqli_error($con))
{
throw new Exception("Cannot Select the database.");
}
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
}
public static function closeConnection($connection)
{
try
{
mysqli_close($connection);
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
}
}
$cone=getConnection::connectToDatabase();
getConnection::selectDatabase($cone);
getConnection::closeConnection($cone);
?>