-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdo_db_connect.inc.php
More file actions
38 lines (38 loc) · 861 Bytes
/
Copy pathpdo_db_connect.inc.php
File metadata and controls
38 lines (38 loc) · 861 Bytes
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
<?php function dbConnect($type) {//defines connection to database with PDO
if ($type == 'query') {
$user = 'query';
$pwd = 'logon';
}
elseif ($type == 'admin') {
$user = 'admin';
$pwd = 'logon';
}
else {
exit('Unrecognized connection type');
}
try {
$conn = new PDO('mysql:host=localhost;dbname=library', $user, $pwd);
return $conn;
}
catch (PDOException $e) {
echo 'Cannot connect to database';
exit;
}
}
//MySQLI version
/*function dbConnect($type) {
if ($type == 'query') {
$user = 'jacobsc1_squery';
$pwd = 'Type_0_Negative@';
}
elseif ($type == 'admin') {
$user = 'jacobsc1_sadmin';
$pwd = 'Type_0_Negative@';
}
else {
exit('Unrecognized connection type');
}
$conn = new mysqli('localhost', $user, $pwd, 'jacobsc1_library') or die ('Cannot open database');
return $conn;
}*/
?>