| @@ 183-204 (lines=22) @@ | ||
| 180 | * |
|
| 181 | * @return bool |
|
| 182 | */ |
|
| 183 | public function update($table, array $elements = [], $conditions = '') |
|
| 184 | { |
|
| 185 | $keys = array_keys($elements); |
|
| 186 | ||
| 187 | if (0 === count($keys)) { |
|
| 188 | return false; |
|
| 189 | } |
|
| 190 | ||
| 191 | $valStr = []; |
|
| 192 | ||
| 193 | foreach ($keys as $key) { |
|
| 194 | $valStr[] = '`'.$key.'` = :'.$key; |
|
| 195 | } |
|
| 196 | ||
| 197 | $valStr = implode(',', $valStr); |
|
| 198 | ||
| 199 | if ($conditions) { |
|
| 200 | $conditions = 'WHERE '.$conditions; |
|
| 201 | } |
|
| 202 | ||
| 203 | return $this->conn->prepare("UPDATE {$table} SET {$valStr} {$conditions};")->execute($elements); |
|
| 204 | } |
|
| 205 | ||
| 206 | /** |
|
| 207 | * Exists element in the table by params |
|
| @@ 191-212 (lines=22) @@ | ||
| 188 | * |
|
| 189 | * @return bool |
|
| 190 | */ |
|
| 191 | public function update($table, array $elements = [], $conditions = '') |
|
| 192 | { |
|
| 193 | $keys = array_keys($elements); |
|
| 194 | ||
| 195 | if (0 === count($keys)) { |
|
| 196 | return false; |
|
| 197 | } |
|
| 198 | ||
| 199 | $valStr = []; |
|
| 200 | ||
| 201 | foreach ($keys as $key) { |
|
| 202 | $valStr[] = '"'.$key.'" = :'.$key; |
|
| 203 | } |
|
| 204 | ||
| 205 | $valStr = implode(',', $valStr); |
|
| 206 | ||
| 207 | if ($conditions) { |
|
| 208 | $conditions = 'WHERE '.$conditions; |
|
| 209 | } |
|
| 210 | ||
| 211 | return $this->conn->prepare("UPDATE {$table} SET {$valStr} {$conditions};")->execute($elements); |
|
| 212 | } |
|
| 213 | ||
| 214 | /** |
|
| 215 | * Exists element in the table by params |
|