-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_util.php
More file actions
71 lines (55 loc) · 1.71 KB
/
db_util.php
File metadata and controls
71 lines (55 loc) · 1.71 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
67
68
69
70
71
<?php
$debugOn = true;
date_default_timezone_set("America/Los_Angeles");
// connect to a mysql db
function wrapper_mysql_connect($environment) {
$local_db = array(
'host' => '127.0.0.1',
'database' => 'link_analyzer',
'username' => 'root',
'password' => 'root');
$dev_db = array(
'host' => '10.89.113.134',
'database' => 'link_analyzer',
'username' => 'pmittal',
'password' => 'password');
global $debugOn;
if ($environment = 'local') {
$inuse_db = $local_db;
} else if ($environment = 'dev') {
$inuse_db = $dev_db;
}
$host = $inuse_db['host'];
$username = $inuse_db['username'];
$password = $inuse_db['password'];
$database = $inuse_db['database'];
$dbConnection = @mysql_connect($host, $username, $password);
if ($debugOn) {
print_r($inuse_db);
echo "\n";
print "Connecting to: Host: " . $host . " User: " . $username . " Password: " . $password . "...\n";
}
if (!$dbConnection || !mysql_select_db($database,$dbConnection)) {
if ($debugOn) {
print "Error connecting to database: " . $database . "\n";
print mysql_error();
echo "\n";
die;
}
//exit;
}
if ($debugOn) {
print "Connected to: Host: " . $host . " User: " . $username . "Password: " . $password . " DB: " . $database ."\n";
}
return $dbConnection;
}
// run a query
function wrapper_mysql_query($sqlQuery, $dbConnection) {
global $debugOn;
if ($debugOn) {
print '<br /><b>Query:</b> DB: ' . $dbConnection . ' SQL:<pre>' . $sqlQuery . '</pre>';
}
$result = mysql_query($sqlQuery, $dbConnection);
return $result;
}
?>