author | Dan |
Tue, 20 Jan 2009 22:08:07 -0500 | |
changeset 51 | 508400fc5282 |
parent 27 | 4a9469bada05 |
permissions | -rw-r--r-- |
27 | 1 |
<?php |
2 |
||
3 |
$mysql_conn = false; |
|
4 |
||
5 |
function mysql_reconnect() |
|
6 |
{ |
|
7 |
global $mysql_conn, $mysql_host, $mysql_user, $mysql_pass, $mysql_dbname; |
|
8 |
if ( $mysql_conn ) |
|
9 |
{ |
|
10 |
@mysql_close($mysql_conn); |
|
11 |
if ( defined('LIBIRC_DEBUG') ) |
|
12 |
{ |
|
13 |
echo "< > Reconnecting to MySQL\n"; |
|
14 |
} |
|
15 |
} |
|
16 |
// connect to MySQL |
|
17 |
$mysql_conn = @mysql_connect($mysql_host, $mysql_user, $mysql_pass); |
|
18 |
if ( !$mysql_conn ) |
|
19 |
{ |
|
20 |
$m_e = mysql_error(); |
|
21 |
echo "Error connecting to MySQL: $m_e\n"; |
|
22 |
exit(1); |
|
23 |
} |
|
24 |
$q = @mysql_query("USE `$mysql_dbname`;", $mysql_conn); |
|
25 |
if ( !$q ) |
|
26 |
{ |
|
27 |
$m_e = mysql_error(); |
|
28 |
echo "Error selecting database: $m_e\n"; |
|
29 |
exit(1); |
|
30 |
} |
|
31 |
} |
|
32 |
||
33 |
function eb_mysql_query($sql, $conn = false) |
|
34 |
{ |
|
35 |
global $mysql_conn, $irc; |
|
36 |
$m_et = false; |
|
37 |
while ( true ) |
|
38 |
{ |
|
39 |
$q = mysql_query($sql, $mysql_conn); |
|
40 |
if ( !$q ) |
|
41 |
{ |
|
42 |
$m_e = mysql_error(); |
|
43 |
if ( strpos($m_e, 'gone away') && !$m_et ) |
|
44 |
{ |
|
45 |
mysql_reconnect(); |
|
46 |
continue; |
|
47 |
} |
|
48 |
$m_et = true; |
|
49 |
// alert everyone on the bot's alert list |
|
50 |
if ( is_object($irc) ) |
|
51 |
{ |
|
51
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
27
diff
changeset
|
52 |
global $permissions; |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
27
diff
changeset
|
53 |
foreach ( $permissions as $nick => $perms ) |
27 | 54 |
{ |
51
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
27
diff
changeset
|
55 |
if ( check_permissions($nick, array('context' => 'alert')) ) |
508400fc5282
Major change to permissions backend - performs whois check (only supported blitzed and freenode right now) and advanced permissions supported.
Dan
parents:
27
diff
changeset
|
56 |
$irc->privmsg($nick, "MySQL query error: $m_e"); |
27 | 57 |
} |
58 |
} |
|
59 |
else |
|
60 |
{ |
|
61 |
echo "\nQUERY ERROR: $m_e\nQuery: $sql\n"; |
|
62 |
exit(1); |
|
63 |
} |
|
64 |
return false; |
|
65 |
} |
|
66 |
break; |
|
67 |
} |
|
68 |
return $q; |
|
69 |
} |
|
70 |
||
71 |
function db_escape($str) |
|
72 |
{ |
|
73 |
return mysql_real_escape_string($str); |
|
74 |
} |