- 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)
This commit is contained in:
@@ -1,41 +1,57 @@
|
||||
<?php
|
||||
function query_appdb($sQuery)
|
||||
function query_appdb($sQuery,$sComment="")
|
||||
{
|
||||
global $hPublicLink;
|
||||
global $hAppdbLink;
|
||||
|
||||
if(!$hPublicLink)
|
||||
if(!$hAppdbLink)
|
||||
{
|
||||
$hPublicLink = mysql_pconnect(APPS_DBHOST, APPS_DBUSER, APPS_DBPASS);
|
||||
$hAppdbLink = mysql_pconnect(APPS_DBHOST, APPS_DBUSER, APPS_DBPASS);
|
||||
mysql_select_db(APPS_DB);
|
||||
}
|
||||
$hResult = mysql_query($sQuery, $hPublicLink);
|
||||
if(!$hResult)
|
||||
{
|
||||
$sStatusMessage = "<p><b>Database Error!<br>".mysql_error()."</b></p>\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 = "<p><b>Database Error!<br>".mysql_error()."</b></p>\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 = "<p><b>Database Error!</b><br />";
|
||||
$sStatusMessage .= $sComment ? $sComment."<br />" : "";
|
||||
$sStatusMessage .= mysql_error()."</p>\n";
|
||||
addmsg($sStatusMessage, "red");
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects an array in this form:
|
||||
* $aFoo['field'] = 'value';
|
||||
|
||||
Reference in New Issue
Block a user