diff --git a/webroot/results/includes/WCAClasses/DBConn.class.php b/webroot/results/includes/WCAClasses/DBConn.class.php
index 0a5f5f83a49..0c90b1b76c5 100644
--- a/webroot/results/includes/WCAClasses/DBConn.class.php
+++ b/webroot/results/includes/WCAClasses/DBConn.class.php
@@ -25,7 +25,7 @@ public function __construct($config, $charset = "utf8")
$this->conn = new \mysqli($config['host'], $config['user'], $config['pass'], $config['name'], $config['port']);
if($this->conn->connect_errno)
{
- trigger_error("Failed to connect to MySQL: (" . $this->conn->connect_errno . ") " . $this->conn->connect_error, E_USER_ERROR);
+ trigger_error("Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error, E_USER_ERROR);
}
// Treat warnings as errors
diff --git a/webroot/results/includes/_config.php.template b/webroot/results/includes/_config.php.template
new file mode 100644
index 00000000000..76c75209110
--- /dev/null
+++ b/webroot/results/includes/_config.php.template
@@ -0,0 +1,38 @@
+get('database');
+
+ #--- Connect to the database server.
+ # TODO: Upgrade
+ mysql_connect( $db_config['host'], $db_config['user'], $db_config['pass'] )
+ or showDatabaseError( "Unable to connect to the database." );
+
+ #--- Select the database.
+ mysql_select_db( $db_config['name'] )
+ or showDatabaseError( "Unable to access the database." );
+
+ dbCommand( "SET NAMES 'utf8'" );
+}
#----------------------------------------------------------------------
function mysqlEscape ( $string ) {
#----------------------------------------------------------------------
- global $wcadb_conn;
- return $wcadb_conn->mysqlEscape($string);
+ return mysql_real_escape_string( $string );
}
#----------------------------------------------------------------------
function dbQuery ( $query ) {
#----------------------------------------------------------------------
- global $wcadb_conn;
- return $wcadb_conn->dbQuery($query);
+
+ startTimer();
+
+ if( wcaDebug() ){
+ startTimer();
+ global $dbQueryCtr;
+ $dbQueryCtr++;
+ echo "\n\n\n\n";
+ echo "
";
+ stopTimer( 'printing the database query' );
+ }
+
+ startTimer();
+ $dbResult = mysql_query( $query )
+ or showDatabaseError( "Unable to perform database query." );
+ stopTimer( "pure database query" );
+
+ startTimer();
+ $rows = array();
+ while( $row = mysql_fetch_array( $dbResult ))
+ $rows[] = $row;
+ stopTimer( "fetching database query results" );
+
+ startTimer();
+ mysql_free_result( $dbResult );
+ stopTimer( "freeing the mysql result" );
+
+ global $dbQueryTotalTime;
+ $dbQueryTotalTime += stopTimer( "the whole dbQuery execution" );
+
+ return $rows;
}
#----------------------------------------------------------------------
function dbQueryHandle ( $query ) {
#----------------------------------------------------------------------
- global $wcadb_conn;
- return $wcadb_conn->dbQuery($query);
+
+ if( wcaDebug() ){
+ startTimer();
+ global $dbQueryCtr;
+ $dbQueryCtr++;
+ echo "\n\n\n\n";
+ echo "
";
+ stopTimer( 'printing the database query' );
+ }
+
+ startTimer();
+ $dbResult = mysql_query( $query )
+ or showDatabaseError( "Unable to perform database query." );
+ global $dbQueryTotalTime;
+ $dbQueryTotalTime += stopTimer( "pure database query" );
+
+ return $dbResult;
}
#----------------------------------------------------------------------
@@ -38,8 +99,24 @@ function dbValue ( $query ) {
#----------------------------------------------------------------------
function dbCommand ( $command ) {
#----------------------------------------------------------------------
- global $wcadb_conn;
- return $wcadb_conn->dbCommand($command);
+
+ if( wcaDebug() ){
+ startTimer();
+ global $dbCommandCtr;
+ $dbCommandCtr++;
+ $commandForShow = strlen($command) < 1010
+ ? $command
+ : substr($command,0,1000) . '[...' . (strlen($command)-1000) . '...]';
+ echo "\n\n\n\n";
+ stopTimer( 'printing the database command' );
+ }
+
+ #--- Execute the command.
+ startTimer();
+ $dbResult = mysql_query( $command )
+ or showDatabaseError( "Unable to perform database command." );
+ global $dbCommandTotalTime;
+ $dbCommandTotalTime += stopTimer( "executing database command" );
}
#----------------------------------------------------------------------
@@ -196,6 +273,16 @@ function dbDebug ( $query ) {
echo "";
}
+#----------------------------------------------------------------------
+function showDatabaseError ( $message ) {
+#----------------------------------------------------------------------
+
+ #--- Normal users just get a "Sorry", developers/debuggers get more details
+ die( $_SERVER['SERVER_NAME'] == 'localhost' || wcaDebug()
+ ? "
$message
\n(" . mysql_error() . ")
Problem with the database, sorry. If this persists for several minutes, " . + "please tell us at contact@worldcubeassociation.org
" ); +} #---------------------------------------------------------------------- function showDatabaseStatistics () {