Exemple #1
0
 /**
  * Return random database resource object
  * @param string $group Group name
  * @return boolean|\Sonic\Model\PDO
  */
 public static function &_getRandomDbResource($group)
 {
     $obj = FALSE;
     while (Sonic::countResourceGroup($group) > 0) {
         $name = Sonic::selectRandomResource($group);
         $obj =& Sonic::getResource(array($group, $name));
         // If a PDO object
         if ($obj instanceof \PDO) {
             // Attempt to connect to the resource
             // This will throw an exception if it fails or break the loop if it succeeds
             if ($obj instanceof Resource\Db) {
                 try {
                     $obj->Connect();
                     // Set as default group object for persistence
                     Sonic::setSelectedResource($group, $name);
                     break;
                 } catch (\PDOException $e) {
                     // Do nothing
                 }
             } else {
                 break;
             }
         }
         // Remove resource from the framework as its not valid
         // then continue to the next object
         Sonic::removeResource($group, $name);
         $obj = FALSE;
     }
     return $obj;
 }