예제 #1
0
 public static function executeUpdateQuery($properties, $table, $primaryKey, $connection = null)
 {
     try {
         if (is_null($connection)) {
             $connection = Connect::getDataInstance();
         }
         $count = 0;
         $sql = "UPDATE " . $table . " SET ";
         foreach ($properties as $key => $value) {
             $count++;
             if ($key == 'id') {
                 continue;
             }
             $sql .= "{$key} = ?";
             if ($count < count($properties)) {
                 $sql .= ", ";
             }
         }
         $sql .= " WHERE " . $primaryKey . " = ?";
         $statement = $connection->prepare($sql);
         $indexCount = 0;
         foreach ($properties as $key => $value) {
             if ($key === 'id') {
                 continue;
             }
             ++$indexCount;
             $statement->bindValue($indexCount, $value);
         }
         $statement->bindValue(++$indexCount, $properties['id']);
         $result = $statement->execute();
     } catch (PDOException $e) {
         return $e->getMessage();
     }
     return $result;
 }
예제 #2
0
 public static function all($table, $connection = null)
 {
     $sql = "SELECT * FROM {$table}";
     if (is_null($connection)) {
         $connection = Connect::getDataInstance();
     }
     $result = $connection->prepare($sql);
     $result->execute();
     return self::toJson($result->fetchAll(PDO::FETCH_ASSOC));
 }
예제 #3
0
 public static function where($column, $value, $table, $connections = null)
 {
     $sql = "SELECT * FROM {$table} WHERE {$column} = '{$value}'";
     if (is_null($connections)) {
         $connections = Connect::getDataInstance();
     }
     $result = $connections->prepare($sql);
     $result->execute();
     return self::toJson($result->fetchAll(PDO::FETCH_ASSOC));
 }