示例#1
0
 public static function update(\PDO $pdo, string $tableName, array $data, array $conditions)
 {
     $table = DbPdoConnector::getTableNameWithPrefix($tableName);
     $fields = array_map(function ($field, $value) {
         return "{$field}='{$value}'";
     }, array_keys($data), array_values($data));
     $fields = implode(', ', $fields);
     $query = "UPDATE `{$table}` SET {$fields}";
     $query .= DefaultFunctions::addConditionsToQuery($conditions);
     return self::execute($pdo->prepare($query));
 }
示例#2
0
文件: FetchData.php 项目: mejt/Krauza
 /**
  * Fetch all records
  *
  * @param \PDO $pdo
  * @param array $columns
  * @param $tableName
  * @param array $where
  * @param array $whereIn
  * @param $limit
  *
  * @return array
  */
 public static function fetchAll(\PDO $pdo, array $columns, string $tableName, array $where = null, array $whereIn = null, int $limit = null) : array
 {
     $query = self::baseQuery($columns, $tableName);
     $query .= $conditions = DefaultFunctions::addConditionsToQuery($where);
     if (!empty($whereIn)) {
         reset($whereIn);
         $key = key($whereIn);
         $in = implode(', ', array_map(function ($el) {
             return "'{$el}'";
         }, current($whereIn)));
         $comm = empty($conditions) ? "WHERE" : "AND";
         $query .= " {$comm} {$key} IN ({$in})";
     }
     if ($limit) {
         $query .= " LIMIT {$limit}";
     }
     return self::executeFetchAllStatement($pdo->prepare($query));
 }