2005-09-07 14:17:16 +02:00
|
|
|
<?
|
|
|
|
|
|
|
|
require_once "config.php";
|
|
|
|
|
|
|
|
function db_connect($host, $user, $pass, $db) {
|
|
|
|
if (DB_TYPE == "pgsql") {
|
|
|
|
|
2005-09-14 04:41:44 +02:00
|
|
|
$string = "dbname=$db user=$user password=$pass";
|
|
|
|
|
|
|
|
if ($host) {
|
2005-09-14 15:37:53 +02:00
|
|
|
$string .= " host=$host";
|
2005-09-14 04:41:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return pg_connect($string);
|
2005-09-07 14:17:16 +02:00
|
|
|
|
|
|
|
} else if (DB_TYPE == "mysql") {
|
2005-09-21 07:38:21 +02:00
|
|
|
$link = mysql_connect($host, $user, $pass) or die(mysql_error());
|
2005-09-07 14:17:16 +02:00
|
|
|
if ($link) {
|
2005-09-21 07:38:21 +02:00
|
|
|
mysql_select_db($db, $link) or die(mysql_error());
|
2005-09-07 14:17:16 +02:00
|
|
|
}
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function db_escape_string($s) {
|
|
|
|
if (DB_TYPE == "pgsql") {
|
|
|
|
return pg_escape_string($s);
|
|
|
|
} else {
|
2005-09-07 15:31:21 +02:00
|
|
|
return mysql_real_escape_string($s);
|
2005-09-07 14:17:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function db_query($link, $query) {
|
|
|
|
if (DB_TYPE == "pgsql") {
|
|
|
|
return pg_query($link, $query);
|
|
|
|
} else if (DB_TYPE == "mysql") {
|
2005-09-21 07:38:21 +02:00
|
|
|
return mysql_query($query, $link) or die(mysql_error());
|
2005-09-07 14:17:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-07 15:31:21 +02:00
|
|
|
function db_query_2($query) {
|
|
|
|
if (DB_TYPE == "pgsql") {
|
|
|
|
return pg_query($query);
|
|
|
|
} else if (DB_TYPE == "mysql") {
|
2005-09-21 07:38:21 +02:00
|
|
|
return mysql_query($link) or die(mysql_error());
|
2005-09-07 15:31:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-07 14:17:16 +02:00
|
|
|
function db_fetch_assoc($result) {
|
|
|
|
if (DB_TYPE == "pgsql") {
|
|
|
|
return pg_fetch_assoc($result);
|
|
|
|
} else if (DB_TYPE == "mysql") {
|
2005-09-21 07:38:21 +02:00
|
|
|
return mysql_fetch_assoc($result) or die(mysql_error());
|
2005-09-07 14:17:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function db_num_rows($result) {
|
|
|
|
if (DB_TYPE == "pgsql") {
|
2005-09-07 15:31:21 +02:00
|
|
|
return pg_num_rows($result);
|
2005-09-07 14:17:16 +02:00
|
|
|
} else if (DB_TYPE == "mysql") {
|
2005-09-07 15:31:21 +02:00
|
|
|
return mysql_num_rows($result);
|
2005-09-07 14:17:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function db_fetch_result($result, $row, $param) {
|
|
|
|
if (DB_TYPE == "pgsql") {
|
|
|
|
return pg_fetch_result($result, $row, $param);
|
|
|
|
} else if (DB_TYPE == "mysql") {
|
|
|
|
// FIXME
|
|
|
|
$line = mysql_fetch_assoc($result);
|
|
|
|
return $line[$param];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function db_close($link) {
|
|
|
|
if (DB_TYPE == "pgsql") {
|
|
|
|
|
|
|
|
return pg_close($link);
|
|
|
|
|
|
|
|
} else if (DB_TYPE == "mysql") {
|
|
|
|
return mysql_close($link);
|
|
|
|
}
|
|
|
|
}
|