1 |
<?php |
<?php |
2 |
include("inc/class.DBI"); |
include("inc/class.DBI"); |
3 |
include("inc/stuff.php"); |
include("inc/stuff.php"); |
4 |
function DBOpen($db = "education", $user = "dpavlin", $pass = "", $opt="") { |
function DBOpen($db = "education", $user = "dpavlin", $pass = "", $host = "localhost") { |
5 |
global $DBD, $DBH; |
global $DBD, $DBH; |
6 |
if ($DBH && $DBH->dbh) return; |
if ($DBH && $DBH->dbh) return; |
7 |
$DBH = new DBI("dbi:$DBD:$db$opt", $user, $pass); |
$str = "dbi:$DBD:$db"; |
8 |
|
if ($host) $str .= ";host=$host"; |
9 |
|
$DBH = new DBI($str, $user, $pass); |
10 |
if (!$DBH->dbh) { |
if (!$DBH->dbh) { |
11 |
$err = $DBH->errstr; |
$err = ""; |
12 |
|
if ($DBH) $DBH->errstr; |
13 |
if (!$err) $err = "???"; |
if (!$err) $err = "???"; |
14 |
echo "[Cannot connect to "$db": $err]<BR>\n"; |
echo "<PRE>[Cannot connect to "$db": $err]</PRE><BR>\n"; |
15 |
unset($DBH); |
unset($GLOBALS['DBH']); |
16 |
|
exit; |
17 |
} |
} |
18 |
$DBH->dbh_do("SET DATESTYLE='ISO'"); |
$DBH->dbh_do("SET DATESTYLE='ISO'"); |
19 |
} |
} |
21 |
global $DBH; |
global $DBH; |
22 |
if (!$DBH || !$DBH->dbh) return; |
if (!$DBH || !$DBH->dbh) return; |
23 |
$DBH->disconnect(); |
$DBH->disconnect(); |
24 |
unset($DBH); |
unset($GLOBALS['DBH']); |
25 |
} |
} |
26 |
function &DBQuery($q) { |
function &DBQuery($q) { |
27 |
global $DBH; |
global $DBH; |
28 |
if (!$DBH || !$DBH->dbh) return array(); |
if (!$DBH || !$DBH->dbh) return array(); |
29 |
|
$DBH->errstr = ""; |
30 |
$ret = array(); |
$ret = array(); |
31 |
if (eregi('^\s*SELECT', $q)) { |
if (eregi('^\s*SELECT', $q)) { |
32 |
$sth = $DBH->prepare($q); |
$sth = $DBH->prepare($q); |