svn: /web/php-bugs/trunk/ bug-pwd-finder.php bug.php bugstats.php fix.php include/config.php include/functions.inc include/prepend.inc lbugs.php
lstats.php report.php rpc.php search.php vote.php

From: Date: Sat, 21 Nov 2009 08:12:02 +0000
Subject: svn: /web/php-bugs/trunk/ bug-pwd-finder.php bug.php bugstats.php fix.php include/config.php include/functions.inc include/prepend.inc lbugs.php
lstats.php report.php rpc.php search.php vote.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-6583@lists.php.net to get a copy of this message
philip Sat, 21 Nov 2009 08:12:02 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=291110 Log: Moved most db connections to one location, start using config info and put it in prepend.inc, and emit a prettier error when the db is down Changed paths: U web/php-bugs/trunk/bug-pwd-finder.php U web/php-bugs/trunk/bug.php U web/php-bugs/trunk/bugstats.php U web/php-bugs/trunk/fix.php D web/php-bugs/trunk/include/config.php U web/php-bugs/trunk/include/functions.inc U web/php-bugs/trunk/include/prepend.inc U web/php-bugs/trunk/lbugs.php U web/php-bugs/trunk/lstats.php U web/php-bugs/trunk/report.php U web/php-bugs/trunk/rpc.php U web/php-bugs/trunk/search.php U web/php-bugs/trunk/vote.php Modified: web/php-bugs/trunk/bug-pwd-finder.php =================================================================== --- web/php-bugs/trunk/bug-pwd-finder.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/bug-pwd-finder.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -8,11 +8,8 @@ if ($bug_id) { - mysql_connect ("localhost","nobody","") - or die("Unable to connect to SQL server. Please try again later."); + db_connect(); - mysql_select_db ("phpbugdb"); - // Clean up the bug id $bug_id = ereg_replace ("[^0-9]+", "", $bug_id); Modified: web/php-bugs/trunk/bug.php =================================================================== --- web/php-bugs/trunk/bug.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/bug.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -25,8 +25,7 @@ list($user,$pw) = explode(":", base64_decode($MAGIC_COOKIE),2); } -@mysql_connect("localhost","nobody","") or die("Unable to connect to SQL server."); -@mysql_select_db("phpbugdb"); +db_connect(); # fetch info about the bug into $bug $query = "SELECT id,bug_type,email,passwd,sdesc,ldesc," Modified: web/php-bugs/trunk/bugstats.php =================================================================== --- web/php-bugs/trunk/bugstats.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/bugstats.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -4,10 +4,7 @@ commonHeader("Statistics"); -@mysql_connect("localhost","nobody","") - or die("unable to connect to database"); -@mysql_select_db("phpbugdb") - or die("unable to select database"); +db_connect(); $sort_by = isset($_GET['sort_by']) ? htmlspecialchars($_GET['sort_by'], ENT_QUOTES) : 'open'; $rev = isset($_GET['rev']) ? (int) $_GET['rev'] : 1; Modified: web/php-bugs/trunk/fix.php =================================================================== --- web/php-bugs/trunk/fix.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/fix.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -70,9 +70,7 @@ exit; } -@mysql_connect("localhost","nobody","") - or die("Unable to connect to SQL server."); -@mysql_select_db("phpbugdb"); +db_connect(); # fetch info about the bug into $bug $query = "SELECT id,bug_type,email,passwd,sdesc,ldesc," Deleted: web/php-bugs/trunk/include/config.php =================================================================== --- web/php-bugs/trunk/include/config.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/include/config.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -1,13 +0,0 @@ -<?php - - -/** - * Database configuration - **/ - -define('BUG_DB_NAME', 'phpbugdb'); -define('BUG_DB_SERVER', 'localhost'); -define('BUG_DB_USER', 'nobody'); -define('BUG_DB_PASS', ''); - - Modified: web/php-bugs/trunk/include/functions.inc =================================================================== --- web/php-bugs/trunk/include/functions.inc 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/include/functions.inc 2009-11-21 08:12:02 UTC (rev 291110) @@ -805,4 +805,15 @@ return '<a ' . $extras . ' href="&#x6d;&#97;&#x69;&#108;&#x74;&#111;&#x3a;' . $tmp . '">' . ($linktext != '' ? $linktext : $tmp) . '</a>'; } -?> + +function db_connect() { + if ($conn = @mysql_connect(BUG_DB_SERVER, BUG_DB_USER, BUG_DB_PASS)) { + if (mysql_select_db(BUG_DB_NAME, $conn)) { + return $conn; + } + } + commonHeader('The bugs system is resting'); + echo '<p>The data center is offline. This might be a feature, and not a bug, but probably not.</p>'; + commonFooter(); + exit; +} Modified: web/php-bugs/trunk/include/prepend.inc =================================================================== --- web/php-bugs/trunk/include/prepend.inc 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/include/prepend.inc 2009-11-21 08:12:02 UTC (rev 291110) @@ -1,5 +1,9 @@ <?php define('DEVBOX', false); +define('BUG_DB_NAME', 'phpbugdb'); +define('BUG_DB_SERVER', 'localhost'); +define('BUG_DB_USER', 'nobody'); +define('BUG_DB_PASS', ''); require_once 'layout.inc'; require_once 'functions.inc'; Modified: web/php-bugs/trunk/lbugs.php =================================================================== --- web/php-bugs/trunk/lbugs.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/lbugs.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -1,9 +1,9 @@ <?php /* vim: set noet ts=4 sw=4: : */ -mysql_connect("localhost","nobody","") - or die("Unable to connect to SQL server\n"); -mysql_select_db("phpbugdb"); +require './include/prepend.inc'; +db_connect(); + if ($id) { $id = (int) $id; $result = mysql_query("SELECT id,bug_type,email,sdesc,ldesc,php_version,php_os,status,ts1,assign FROM bugdb WHERE id=$id"); Modified: web/php-bugs/trunk/lstats.php =================================================================== --- web/php-bugs/trunk/lstats.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/lstats.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -1,5 +1,9 @@ <?php /* vim: set noet ts=4 sw=4: : */ +require './include/prepend.inc'; + +db_connect(); + function status_print ($status, $num, $width, $align='left') { $str = ucfirst($status).":"; $str.= str_repeat(" ", $width - strlen($str) + (($align == 'right') ? (4 - strlen($num)) : 0)); @@ -53,9 +57,6 @@ echo "<h3>Bug stats for PHP $phpver:</h3>\n<pre>\n"; } -mysql_connect("localhost","nobody",""); -mysql_select_db("phpbugdb"); - if (isset($per_category)) { include ('bugtypes.inc'); Modified: web/php-bugs/trunk/report.php =================================================================== --- web/php-bugs/trunk/report.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/report.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -22,9 +22,7 @@ $mail_bugs_to = "php-bugs@lists.php.net"; -@mysql_connect("localhost","nobody","") - or die("Unable to connect to SQL server."); -@mysql_select_db("phpbugdb"); +db_connect(); $errors = array(); if ($in) { Modified: web/php-bugs/trunk/rpc.php =================================================================== --- web/php-bugs/trunk/rpc.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/rpc.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -6,6 +6,7 @@ exit; } +require './include/prepend.inc'; require './include/auth.inc'; if (isset($_POST['MAGIC_COOKIE'])) { @@ -20,8 +21,7 @@ exit; } -@mysql_connect("localhost","nobody","") or die("Unable to connect to SQL server."); -@mysql_select_db("phpbugdb"); +db_connect(); @mysql_set_charset('utf8'); # fetch info about the bug into $bug Modified: web/php-bugs/trunk/search.php =================================================================== --- web/php-bugs/trunk/search.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/search.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -19,10 +19,9 @@ define('BOOLEAN_SEARCH', $boolean); if (isset($cmd) && $cmd == "display") { - @mysql_connect("localhost","nobody","") - or die("Unable to connect to SQL server."); - @mysql_select_db("phpbugdb"); + db_connect(); + $mysql4 = version_compare(mysql_get_server_info(), "4.0.0", "ge"); if (!$bug_type || !is_array($bug_type)) $bug_type = array(); Modified: web/php-bugs/trunk/vote.php =================================================================== --- web/php-bugs/trunk/vote.php 2009-11-21 07:58:01 UTC (rev 291109) +++ web/php-bugs/trunk/vote.php 2009-11-21 08:12:02 UTC (rev 291110) @@ -17,9 +17,7 @@ $samever = (int)$samever; $sameos = (int)$sameos; -@mysql_connect("localhost","nobody","") - or die("Unable to connect to SQL server."); -@mysql_select_db("phpbugdb"); +db_connect(); $query = "SELECT id FROM bugdb WHERE id=" . $id . " LIMIT 1"; $res = mysql_num_rows(mysql_query($query));

« previous php.webmaster (#6583) next »