-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql.php
40 lines (36 loc) · 962 Bytes
/
mysql.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
<?php
require_once "config.inc";
/* Sets up mysql */
$MYSQL_LOCK = "SELECT GET_LOCK('update', 10)";
$MYSQL_UNLOCK = "SELECT RELEASE_LOCK('update')";
function db_connect()
{
global $MYSQL_HOST;
global $MYSQL_USER;
global $MYSQL_PASS;
$mysqli = new mysqli($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS);
if ($mysqli->connect_errno) {
print "<b>Failed to connect to MySQL: " . $mysqli->connect_error . "</b><br/>\n";
return FALSE;
}
if ($mysqli->select_db("trees") === FALSE) {
print "<b>select_db() failed</b><br/>\n";
$mysqli->close();
return FALSE;
}
$result = $mysqli->query("SELECT DATABASE()");
if ($result !== FALSE) {
$row = $result->fetch_row();
if ($row[0] != "trees") {
print "<b>Unable to select database</b><br/>\n";
$mysqli->close();
return FALSE;
}
} else {
print "<b>SELECT DATABASE() failed</b><br/>\n";
$mysqli->close();
return FALSE;
}
return $mysqli;
}
?>