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