예제 #1
0
 /**
  * Create an instance by the hash value. This function is in support
  * of the synchronization functionality. It takes a hash value and
  * it will return an instance of the object for that hash value
  * if the hash exists. If the hash does not exist, null will be
  * returned, indicating that the object should be created using the
  * normal constructor.
  */
 public static function findByHash($hash = '')
 {
     if (!isset($hash) || $hash === '') {
         return null;
     }
     $hashValue = db_sql_encode($hash);
     $query = "SELECT * FROM blogTrip " . "WHERE hash={$hashValue} " . "ORDER BY updated DESC " . "LIMIT 1";
     $result = mysql_query($query);
     if (!$result) {
         // Error executing the query
         print $query . "<br/>";
         print " --> error: " . mysql_error() . "<br/>\n";
         return null;
     }
     if (mysql_num_rows($result) <= 0) {
         // Object does not exist
         return null;
     }
     // Create an instance with a special ID '-' to bypass the
     // checks on empty ID. The ID value will be overwritten by the
     // value coming back from the database anyway.
     $object = new Trip('-');
     if ($object->loadFromResult($result)) {
         return $object;
     }
     return null;
 }