Exemplo n.º 1
0
function GetSingleByCondition($table, $condition, $orderBy = null)
{
    if ($orderBy != null) {
        $orderBy = " ORDER BY " . $orderBy;
    }
    $model = GetModelByTable($table);
    $db = GetDatabaseConnection();
    $stmt = $db->prepare('SELECT * FROM ' . $table . ConstructConditionSQL($condition) . $orderBy . " LIMIT 1");
    $stmt->execute($condition);
    $result = $stmt->fetchAll(PDO::FETCH_CLASS, $model);
    if (isset($result[0])) {
        return $result[0];
    } else {
        return false;
    }
}
 /**
  * @param $noteTakerGuid
  * @return NoteCollection[]
  */
 private function tryAddNoteTaker($noteTakerGuid)
 {
     $db = GetDatabaseConnection();
     $pdo = $db->prepare("SELECT * FROM NoteTakers WHERE NoteTakers.Guid = :NoteTakerGuid");
     $pdo->bindValue(":NoteTakerGuid", $noteTakerGuid);
     $pdo->execute();
     $takers = $pdo->fetchAll(PDO::FETCH_CLASS, GetModelByTable("NoteTakers"));
     if (count($takers) == 0) {
         $taker = new NoteTaker();
         $taker->Guid = $noteTakerGuid;
         return Insert("NoteTakers", $taker);
     }
     return true;
 }