mirror of
https://codeberg.org/vlw/php-mysql.git
synced 2025-09-14 00:33:41 +02:00
Compare commits
5 commits
Author | SHA1 | Date | |
---|---|---|---|
73297feb82 | |||
0e367f797f | |||
ddcd8a2961 | |||
e062930c41 | |||
814070a52e |
2 changed files with 12 additions and 16 deletions
|
@ -15,7 +15,7 @@ which would be equivalent to the following in MySQL:
|
|||
SELECT `columns` FROM `table` WHERE `filter` ORDER BY `order_by` LIMIT `limit`;
|
||||
```
|
||||
|
||||
- All methods can be chained in any order (even multiple times) after a [`for()`](#for) as long as a [`select()`](#select), [`insert()`](#insert), [`update()`](#update), or [`delete()`](#delete) is the last method.
|
||||
- All methods can be chained in any order (even multiple times) after a [`from()`](#from) as long as a [`select()`](#select), [`insert()`](#insert), [`update()`](#update), or [`delete()`](#delete) is the last method.
|
||||
- Chaining the same method more than once will override its previous value. Passing `null` to any method that accepts it will unset its value completely.
|
||||
|
||||
## Install from composer
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
*/
|
||||
|
||||
private function throw_if_no_table() {
|
||||
if (!$this->table) {
|
||||
if (!isset($this->table)) {
|
||||
throw new Exception("No table name defined");
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@
|
|||
since: "3.5.7",
|
||||
)]
|
||||
public function for(string $table): self {
|
||||
$this->from($table);
|
||||
return $this->from($table);
|
||||
}
|
||||
|
||||
// Create a WHERE statement from filters
|
||||
|
@ -163,17 +163,8 @@
|
|||
return $this;
|
||||
}
|
||||
|
||||
// Set LIMIT without range directly as integer
|
||||
if (is_int($limit)) {
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// No offset defined, set limit property directly as string
|
||||
if (is_null($offset)) {
|
||||
$this->limit = (string) $limit;
|
||||
return $this;
|
||||
}
|
||||
// Coerce offset to zero if no offset is defined
|
||||
$offset = $offset ?? 0;
|
||||
|
||||
// Set limit and offset as SQL CSV
|
||||
$this->limit = "{$offset},{$limit}";
|
||||
|
@ -277,9 +268,14 @@
|
|||
$this->throw_if_no_table();
|
||||
|
||||
// Set DELETE WHERE conditions from arguments
|
||||
$this->where(...$conditions);
|
||||
if ($conditions) {
|
||||
$this->where(...$conditions);
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM `{$this->table}` WHERE {$this->filter_sql}";
|
||||
// Get array of SQL WHERE string and filter values
|
||||
$filter_sql = !is_null($this->filter_sql) ? " WHERE {$this->filter_sql}" : "";
|
||||
|
||||
$sql = "DELETE FROM `{$this->table}`{$filter_sql}";
|
||||
return $this->execute_query($sql, self::to_list_array($this->filter_values));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue