From bfd43bda12f6b9caa5be06fd545c8182dcbc2c74 Mon Sep 17 00:00:00 2001
From: Jonathan Ernst
Date: Wed, 12 Jan 2005 02:43:52 +0000
Subject: [PATCH] - added an optional parameter to query_*() in order to show
more informations about the error and to avoid to make the error handling in
the other scripts - added query_bugzilladb to query bugzilla's db so we can
get rid of the last mysql_query in the code - factorized duplicated code
(query_error)
---
include/db.php | 54 ++++++++++++++++++++++++++++++++------------------
1 file changed, 35 insertions(+), 19 deletions(-)
diff --git a/include/db.php b/include/db.php
index ca89305..02d1dcb 100644
--- a/include/db.php
+++ b/include/db.php
@@ -1,41 +1,57 @@
Database Error!
".mysql_error()."
\n";
- addmsg($sStatusMessage, "red");
- }
+ $hResult = mysql_query($sQuery, $hAppdbLink);
+ if(!$hResult) query_error($sComment);
return $hResult;
}
function query_userdb($sQuery)
{
- global $hPrivateLink;
+ global $hUserLink;
- if(!$hPrivateLink)
+ if(!$hUserLink)
{
- $hPrivateLink = mysql_pconnect(USERS_DBHOST, USERS_DBUSER, USERS_DBPASS);
+ $hUserLink = mysql_pconnect(USERS_DBHOST, USERS_DBUSER, USERS_DBPASS);
mysql_select_db(USERS_DB);
}
- $hResult = mysql_query($sQuery, $hPrivateLink);
- if(!$hResult)
- {
- $sStatusMessage = "Database Error!
".mysql_error()."
\n";
- addmsg($sStatusMessage, "red");
- }
+ $hResult = mysql_query($sQuery, $hUserLink);
+ if(!$hResult) query_error($sComment);
return $hResult;
}
+
+function query_bugzilladb($sQuery,$sComment="")
+{
+ global $hBugzillaLink;
+
+ if(!$hBugzillaLink)
+ {
+ $hBugzillaLink = mysql_pconnect(BUGZILLA_DBHOST, BUGZILLA_DBUSER, BUGZILLA_DBPASS);
+ mysql_select_db(BUGZILLA_DB);
+ }
+ $hResult = mysql_query($sQuery, $hBugzillaLink);
+ if(!$hResult) query_error($sComment);
+ return $hResult;
+}
+
+
+function query_error($sComment="")
+{
+ $sStatusMessage = "Database Error!
";
+ $sStatusMessage .= $sComment ? $sComment."
" : "";
+ $sStatusMessage .= mysql_error()."
\n";
+ addmsg($sStatusMessage, "red");
+}
+
/**
* Expects an array in this form:
* $aFoo['field'] = 'value';