From 8dfb66fd0932b780b73d9ad6e4186635d25453c8 Mon Sep 17 00:00:00 2001 From: "Leigh B. Stoller" <stoller@flux.utah.edu> Date: Sat, 22 Jun 2002 00:19:23 +0000 Subject: [PATCH] Remove a bunch of uses of mysql_db_query(), converting to DBQueryFatal(). This call appears to always reselect the DB, which might be a problem when the DB is busy. --- www/approveproject_list.php3 | 11 ++----- www/dbdefs.php3.in | 3 +- www/nodemon.php3 | 7 +---- www/nodemon_all.php3 | 7 +---- www/projectlist.php3 | 28 +++++++----------- www/showproject.php3 | 56 ++++++++++++++++++------------------ www/showproject_dump.php3 | 7 ++--- www/showstuff.php3 | 27 ++++++++--------- 8 files changed, 60 insertions(+), 86 deletions(-) diff --git a/www/approveproject_list.php3 b/www/approveproject_list.php3 index 78b1dc8e1f..35b35158be 100755 --- a/www/approveproject_list.php3 +++ b/www/approveproject_list.php3 @@ -27,12 +27,7 @@ if (! $isadmin) { # implies denying the project leader account, when there is just a single # project pending for that project leader. # -$query_result = mysql_db_query($TBDBNAME, - "SELECT * from projects where approved='0'"); -if (! $query_result) { - $err = mysql_error(); - TBERROR("Database Error getting unapproved project list: $err\n", 1); -} +$query_result = DBQueryFatal("SELECT * from projects where approved='0'"); if (mysql_num_rows($query_result) == 0) { USERERROR("There are no projects to approve!", 1); } @@ -65,8 +60,8 @@ while ($projectrow = mysql_fetch_array($query_result)) { $Purl = $projectrow[URL]; $Pname = $projectrow[name]; - $userinfo_result = mysql_db_query($TBDBNAME, - "SELECT * from users where uid=\"$headuid\""); + $userinfo_result = + DBQueryFatal("SELECT * from users where uid='$headuid'"); $row = mysql_fetch_array($userinfo_result); $name = $row[usr_name]; diff --git a/www/dbdefs.php3.in b/www/dbdefs.php3.in index 64f7fef018..7f7526644c 100644 --- a/www/dbdefs.php3.in +++ b/www/dbdefs.php3.in @@ -1195,8 +1195,9 @@ function DBQuery($query) { global $TBDBNAME; global $DBErrorString; + global $DBlinkid; - $result = mysql_db_query($TBDBNAME, $query); + $result = mysql_query($query, $DBlinkid); if (! $result) { $DBErrorString = diff --git a/www/nodemon.php3 b/www/nodemon.php3 index 2125b8c260..482215a8e4 100644 --- a/www/nodemon.php3 +++ b/www/nodemon.php3 @@ -15,12 +15,7 @@ if (!isset($nid) || } $pid = addslashes($pid); -$query_result = mysql_db_query($TBDBNAME, - "SELECT * from wires where node_id1='$nid'"); -if (! $query_result) { - $err = mysql_error(); - TBERROR("Database Error getting node information: $err\n", 1); -} +$query_result = DBQueryFatal("SELECT * from wires where node_id1='$nid'"); echo "<table border=1 padding=1>\n"; echo "<tr> diff --git a/www/nodemon_all.php3 b/www/nodemon_all.php3 index ecbc9db355..b7fbd38ec5 100644 --- a/www/nodemon_all.php3 +++ b/www/nodemon_all.php3 @@ -15,12 +15,7 @@ if (!isset($nid) || } $pid = addslashes($pid); -$query_result = mysql_db_query($TBDBNAME, - "SELECT * from wires where node_id1='$nid'"); -if (! $query_result) { - $err = mysql_error(); - TBERROR("Database Error getting node information: $err\n", 1); -} +$query_result = DBQueryFatal("SELECT * from wires where node_id1='$nid'"); echo "<table border=1 padding=1>\n"; echo "<tr> diff --git a/www/projectlist.php3 b/www/projectlist.php3 index e036488498..dbd1769a2a 100644 --- a/www/projectlist.php3 +++ b/www/projectlist.php3 @@ -51,15 +51,11 @@ function GENPLIST ($query_result) # # Get the "active" project list. # -$query_result = mysql_db_query($TBDBNAME, - "SELECT pid,name,URL,usr_affil FROM projects ". - "left join users on projects.head_uid=users.uid ". - "where public=1 and approved=1 and expt_count>0 order by name"); - -if (! $query_result) { - $err = mysql_error(); - TBERROR("Database Error getting active project list: $err\n", 1); -} +$query_result = + DBQueryFatal("SELECT pid,name,URL,usr_affil FROM projects ". + "left join users on projects.head_uid=users.uid ". + "where public=1 and approved=1 and expt_count>0 ". + "order by name"); echo "<table width=\"100%\" border=0 cellpadding=2 cellspacing=2 align='center'>\n"; @@ -71,15 +67,11 @@ if (mysql_num_rows($query_result)) { # # Get the "inactive" project list. # -$query_result = mysql_db_query($TBDBNAME, - "SELECT pid,name,URL,usr_affil FROM projects ". - "left join users on projects.head_uid=users.uid ". - "where public=1 and approved=1 and expt_count=0 order by name"); - -if (! $query_result) { - $err = mysql_error(); - TBERROR("Database Error getting inactive project list: $err\n", 1); -} +$query_result = + DBQueryFatal("SELECT pid,name,URL,usr_affil FROM projects ". + "left join users on projects.head_uid=users.uid ". + "where public=1 and approved=1 and expt_count=0 ". + "order by name"); if (mysql_num_rows($query_result)) { echo "<tr></tr>\n"; diff --git a/www/showproject.php3 b/www/showproject.php3 index 0928764d44..e794bd66bc 100644 --- a/www/showproject.php3 +++ b/www/showproject.php3 @@ -47,7 +47,32 @@ if (! TBProjAccessCheck($uid, $pid, $pid, $TB_PROJECT_READINFO)) { USERERROR("You are not a member of Project $pid.", 1); } -SHOWPROJECT($pid, $uid); +# +# A list of project experiments. +# +$query_result = + DBQueryFatal("SELECT eid,expt_name FROM experiments WHERE pid='$pid' order by eid"); +if (mysql_num_rows($query_result)) { + echo "<center> + <h3>Project Experiments</h3> + </center> + <table align=center border=1>\n"; + + while ($row = mysql_fetch_row($query_result)) { + $eid = $row[0]; + $name = $row[1]; + if (!$name) + $name = "--"; + echo "<tr> + <td> + <A href='showexp.php3?pid=$pid&eid=$eid'>$eid</a> + </td> + <td>$name</td> + </tr>\n"; + } + + echo "</table>\n"; +} # # A list of project members (from the default group). @@ -96,33 +121,6 @@ if (mysql_num_rows($query_result)) { echo "</table>\n"; } -# -# A list of project experiments. -# -$query_result = - DBQueryFatal("SELECT eid,expt_name FROM experiments WHERE pid='$pid' order by eid"); -if (mysql_num_rows($query_result)) { - echo "<center> - <h3>Project Experiments</h3> - </center> - <table align=center border=1>\n"; - - while ($row = mysql_fetch_row($query_result)) { - $eid = $row[0]; - $name = $row[1]; - if (!$name) - $name = "--"; - echo "<tr> - <td> - <A href='showexp.php3?pid=$pid&eid=$eid'>$eid</a> - </td> - <td>$name</td> - </tr>\n"; - } - - echo "</table>\n"; -} - # # A list of project Groups (if more than just the default). # @@ -164,6 +162,8 @@ echo "<p><center> <A href='newgroup_form.php3?pid=$pid'>Create</a> a new Group? </center>\n"; +SHOWPROJECT($pid, $uid); + if ($isadmin) { echo "<p> <A href='deleteproject.php3?pid=$pid'> diff --git a/www/showproject_dump.php3 b/www/showproject_dump.php3 index 5ad85e9faa..aa33aa13b3 100644 --- a/www/showproject_dump.php3 +++ b/www/showproject_dump.php3 @@ -2,8 +2,7 @@ # # This is an included file. No headers or footers or includes! # -$query_result = - DBQueryFatal("SELECT * FROM projects WHERE pid='$pid'"); +$query_result = DBQueryFatal("SELECT * FROM projects WHERE pid='$pid'"); if (mysql_num_rows($query_result) == 0) { USERERROR("The project $pid is not a valid project.", 1); } @@ -91,8 +90,8 @@ echo "<tr> echo "</table>\n"; -$userinfo_result = mysql_db_query($TBDBNAME, - "SELECT * from users where uid=\"$proj_head_uid\""); +$userinfo_result = + DBQueryFatal("SELECT * from users where uid='$proj_head_uid'"); $row = mysql_fetch_array($userinfo_result); $usr_expires = $row[usr_expires]; diff --git a/www/showstuff.php3 b/www/showstuff.php3 index 81beb57164..c041c43049 100644 --- a/www/showstuff.php3 +++ b/www/showstuff.php3 @@ -11,11 +11,8 @@ function SHOWPROJECT($pid, $thisuid) { global $TBDBNAME; - $query_result = mysql_db_query($TBDBNAME, - "SELECT * FROM projects WHERE pid=\"$pid\""); - if (mysql_num_rows($query_result) == 0) { - USERERROR("The project $pid is not a valid project.", 1); - } + $query_result = + DBQueryFatal("SELECT * FROM projects WHERE pid='$pid'"); $row = mysql_fetch_array($query_result); echo "<center> @@ -319,9 +316,9 @@ function SHOWGROUPMEMBERSHIP($uid) { # function SHOWUSER($uid) { global $TBDBNAME; - - $userinfo_result = mysql_db_query($TBDBNAME, - "SELECT * from users where uid=\"$uid\""); + + $userinfo_result = + DBQueryFatal("SELECT * from users where uid='$uid'"); $row = mysql_fetch_array($userinfo_result); $usr_expires = $row[usr_expires]; @@ -587,9 +584,9 @@ function SHOWNODES($pid, $eid) { global $TBDBNAME; global $TBOPSPID; - $reserved_result = mysql_db_query($TBDBNAME, - "SELECT * FROM reserved WHERE ". - "eid=\"$eid\" and pid=\"$pid\""); + $reserved_result = + DBQueryFatal("SELECT * FROM reserved WHERE ". + "eid='$eid' and pid='$pid'"); # If this is an expt in emulab-ops, we don't care about vname, # since it won't be defined. But we do want to know when the node @@ -620,8 +617,8 @@ function SHOWNODES($pid, $eid) { <td align=center>Ready<br>Status[<b>3</b>]</td> </tr>\n"; - $query_result = mysql_db_query($TBDBNAME, - "SELECT nodes.*,reserved.vname, ". + $query_result = + DBQueryFatal("SELECT nodes.*,reserved.vname, ". "date_format(rsrv_time,\"%Y-%m-%d %T\") as rsrvtime ". "FROM nodes LEFT JOIN reserved ". "ON nodes.node_id=reserved.node_id ". @@ -698,8 +695,8 @@ function SHOWNODES($pid, $eid) { function SHOWOSINFO($osid) { global $TBDBNAME; - $query_result = mysql_db_query($TBDBNAME, - "SELECT * FROM os_info WHERE osid='$osid'"); + $query_result = + DBQueryFatal("SELECT * FROM os_info WHERE osid='$osid'"); $osrow = mysql_fetch_array($query_result); -- GitLab