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