/**
  * Tries to mutate this object to have all the traits of the apiKey defined in the parameters (as loaded from the
  * database).
  *
  * @param apiKey - string - the API key to load from the API Gate database.
  * @param useMaster - boolean - if true, this will use the master database to load the data (useful if you've made changes to the key on the exact same pageload).
  * @return boolean - true if the key was found & loaded, false if the key was not found in the database.
  */
 public function loadFromDb($apiKey, $useMaster = false)
 {
     $wasLoaded = false;
     $db = $useMaster ? ApiGate_Config::getMasterDb() : ApiGate_Config::getSlaveDb();
     $queryString = "SELECT * FROM " . ApiGate::TABLE_KEYS . " WHERE apiKey='" . mysql_real_escape_string($apiKey, $db) . "'";
     if ($result = mysql_query($queryString, $db)) {
         if (($numRows = mysql_num_rows($result)) && $numRows > 0) {
             for ($cnt = 0; $cnt < $numRows; $cnt++) {
                 $this->apiKey = $apiKey;
                 $this->userId = mysql_result($result, $cnt, "user_id");
                 $this->nickName = mysql_result($result, $cnt, "nickName");
                 $this->enabled = mysql_result($result, $cnt, "enabled") != "0";
                 $this->email = mysql_result($result, $cnt, "email");
                 $this->firstName = mysql_result($result, $cnt, "firstName");
                 $this->lastName = mysql_result($result, $cnt, "lastName");
                 $this->reasonBanned = null;
                 // clear it out to be lazy-loaded later
             }
             $wasLoaded = true;
         }
     }
     return $wasLoaded;
 }
示例#2
0
 /**
  * Returns the result of a READ-ONLY mySQL query that only has one result (one column and one row)
  *
  * NOTE: for READ-ONLY operations
  */
 public static function simpleQuery($queryString)
 {
     wfProfileIn(__METHOD__);
     $dbr = ApiGate_Config::getSlaveDb();
     $retVal = "";
     if ($result = mysql_query($queryString, $dbr)) {
         if (mysql_num_rows($result) > 0) {
             if ($myRow = mysql_fetch_row($result)) {
                 $retVal = $myRow[0];
             }
         }
     } else {
         ApiGate::queryError($queryString, $dbr);
     }
     wfProfileOut(__METHOD__);
     return $retVal;
 }