migrate /projects to mysqli

Change-Id: I41bbfa3a4e13f95b0ad65c9bb3fc80fbe08bd7e5
Signed-off-by: Christopher Guindon <chris.guindon@eclipse-foundation.org>
diff --git a/classes/database.inc b/classes/database.inc
index b58991b..d0a1f62 100644
--- a/classes/database.inc
+++ b/classes/database.inc
@@ -10,6 +10,8 @@
  * *****************************************************************************
  */
 
+require_once $_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php";
+
 /**
  * This function provides a means of more-or-less completely abstracting the
  * database when executing a query (callers are still required to provide SQL
@@ -26,66 +28,39 @@
  * All resources that are allocated by the function are closed before the
  * function exits.
  *
+ * Note: For local development, see comments in App::_constructor() for
+ * instructions on how to override databases and other settings.
+ *
  * @param string $database
- *        The name of the database.
+ *   The name of the database.
  * @param string $sql
- *        The query.
+ *   The query.
  * @param mixed $variables
- *        An associative array of variable substitutions.
+ *   An associative array of variable substitutions.
  * @param callable $each
- *        A function that takes a single row as its only parameter.
+ *   A function that takes a single row as its only parameter.
+ *
  * @return void
  */
 function query($database, $sql, $variables, $each) {
   global $App;
-  if (function_exists('mysql_connect')) {
-    $substitutions = array();
-    if ($variables) {
-     // Database connections are created lazily, so it's
-     // possible that we may not have an actual database
-     // connection when we try to call mysql_real_escape_string.
-     // Call App::database to ensure that a connection exists.
-     $App->database($database,'');
-     foreach ($variables as $key => $value) {
-        $substitutions[$key] = mysql_real_escape_string($value);
-      }
-    }
-
-    if ($result = $App->sql(strtr($sql, $substitutions), $database)) {
-      while ($row = mysql_fetch_assoc($result)) {
-        $each($row);
-      }
-    }
-    return;
-  }
-
-  // TODO this will only work in the development environment.
-  $mysqli = new mysqli('localhost', 'dashboard', 'draobhsad', "{$database}_demo");
-  if ($mysqli->connect_errno) {
-    printf("Connect failed: %s\n", $mysqli->connect_error);
-    exit();
-  }
-
-  mysqli_set_charset ($mysqli , "utf8");
-
   $substitutions = array();
+
   if ($variables) {
+    // Database connections are created lazily, so it's
+    // possible that we may not have an actual database
+    // connection when we try to call mysql_real_escape_string.
+    // Call App::database to ensure that a connection exists.
+    $App->database($database, '');
     foreach ($variables as $key => $value) {
-      $substitutions[$key] = $mysqli->escape_string($value);
+      $substitutions[$key] = $App->sqlSanitize($value);
     }
   }
 
-  $statement = strtr($sql, $substitutions);
-  if ($result = $mysqli->query($statement)) {
-    while ($row = $result->fetch_assoc()) {
+  if ($result = $App->sql(strtr($sql, $substitutions), $database)) {
+    while ($row = mysqli_fetch_assoc($result)) {
       $each($row);
     }
-    $result->free();
   }
-  else {
-    printf("Query failed: %s\n", $mysqli->error);
-  }
-
-  $mysqli->close();
+  return;
 }
-?>
\ No newline at end of file
diff --git a/committers-alumni.php b/committers-alumni.php
index c57e4ea..03381bb 100644
--- a/committers-alumni.php
+++ b/committers-alumni.php
@@ -13,10 +13,10 @@
 
 <h1>Eclipse Committers Alumni</h1>
 <p>
-When Committers who have contributed to Eclipse 
+When Committers who have contributed to Eclipse
 become inactive and thus no longer Committers<sup>1</sup>, we want to make sure that we acknowledge their
- contributions to our (collective) success. We choose to make that acknowledgement 
- here on the list of our <em>Committer Alumni</em>. 
+ contributions to our (collective) success. We choose to make that acknowledgement
+ here on the list of our <em>Committer Alumni</em>.
 <p>
 Our thanks to each of these people and their
  contributions to the long term success
@@ -38,7 +38,7 @@
 		  ";
 $result = $App->foundation_sql($sql);
 $emeritus = array();
-while( $row = mysql_fetch_assoc($result) ) {
+while( $row = mysqli_fetch_assoc($result) ) {
 	$emeritus[$row['PID']] = 1;
 }
 $sql = "SELECT People.PersonID as PID, FName, LName, ProjectID FROM People, PeopleProjects
@@ -52,7 +52,7 @@
 		  ";
 $result = $App->foundation_sql($sql);
 $people = array();
-while( $row = mysql_fetch_assoc($result) ) {
+while( $row = mysqli_fetch_assoc($result) ) {
 	$people[] = $row;
 }
 function sortbyproject( $a, $b ) {
@@ -86,8 +86,8 @@
 				?></ul></li>
 				<?php
 			}
-			?><li><a onclick="toggleshow('<?= $row['ProjectID'] ?>')" 
-			style="font-weight: normal"><?= $row['ProjectID'] ?></a><ul 
+			?><li><a onclick="toggleshow('<?= $row['ProjectID'] ?>')"
+			style="font-weight: normal"><?= $row['ProjectID'] ?></a><ul
 				id="<?= $row['ProjectID'] ?>" style="display: none"><?php
 			$showing = $row['ProjectID'];
 		}
@@ -124,8 +124,8 @@
 <p>
 <hr style="margin-top: 5px; margin-bottom: 5px;"/>
 <div style="font-size: 60%"><sup>1</sup>
-Being a Committer is a privilege that is earned by 
-contributing actively, and showing discipline and good judgment. It is a responsibility 
+Being a Committer is a privilege that is earned by
+contributing actively, and showing discipline and good judgment. It is a responsibility
 that is not given, nor be treated, lightly. At the same
 time, we acknowledge that active participation in Eclipse Projects
 is not a lifetime commitment, and thus Committers may/will become
diff --git a/committers-emeritus.php b/committers-emeritus.php
index 6acadf8..7a82ead 100644
--- a/committers-emeritus.php
+++ b/committers-emeritus.php
@@ -37,7 +37,7 @@
 		  ";
 $result = $App->foundation_sql($sql);
 $showing = -1;
-while( $row = mysql_fetch_assoc($result) ) {
+while( $row = mysqli_fetch_assoc($result) ) {
 	if( $showing == $row['PID'] ) {
 		?>, <?= $row['ProjectID'] ?><?php
 	} else {
diff --git a/export/committers.json.php b/export/committers.json.php
index 3207cda..94caecb 100644
--- a/export/committers.json.php
+++ b/export/committers.json.php
@@ -104,7 +104,7 @@
     $committer['email'][] = $email;
 }
 
-while ($row=mysql_fetch_assoc($result)) {
+while ($row=mysqli_fetch_assoc($result)) {
     $id = utf8_encode($row['id']);
     $data['committers'][$id]['id'] = $id;
     $data['committers'][$id]['first'] = utf8_encode($row['FName']);
@@ -151,7 +151,7 @@
 	$data['_errors'][] = 'Error encountered while querying history table.';
 } else {
 	$count = 0;
-	while ($row=mysql_fetch_assoc($result)) {
+	while ($row=mysqli_fetch_assoc($result)) {
 	    $id = $row['id'];
 	    if (!$id) continue;
 	    if (!isset($data['committers'][$id])) continue;
diff --git a/export/updates.json.php b/export/updates.json.php
index ad99a99..7330757 100644
--- a/export/updates.json.php
+++ b/export/updates.json.php
@@ -82,7 +82,7 @@
 
 $result = $App->foundation_sql($sql);
 
-while ($row=mysql_fetch_assoc($result)) {
+while ($row=mysqli_fetch_assoc($result)) {
 	$id =  utf8_encode($row['id']);
 	$people[$id]['id'] = $id;
 	$people[$id]['first'] = $row['FName'];
@@ -118,7 +118,7 @@
 		where relation in ('EA', 'AZ')";
 
 $result = $App->foundation_sql($sql);
-while ($row=mysql_fetch_assoc($result)) {
+while ($row=mysqli_fetch_assoc($result)) {
 	$id =  utf8_encode($row['id']);
 
 	$people[$id]['id'] = $id;
@@ -144,7 +144,7 @@
 		where relation in ('AC')";
 
 $result = $App->foundation_sql($sql);
-while ($row=mysql_fetch_assoc($result)) {
+while ($row=mysqli_fetch_assoc($result)) {
 	$id =  utf8_encode($row['id']);
 
 	$people[$id]['id'] = $id;