| @@ 894-924 (lines=31) @@ | ||
| 891 | * @return false|int |
|
| 892 | * <p>false on error</p> |
|
| 893 | */ |
|
| 894 | public function delete(string $table, $where, string $databaseName = null) |
|
| 895 | { |
|
| 896 | // init |
|
| 897 | $table = \trim($table); |
|
| 898 | ||
| 899 | if ($table === '') { |
|
| 900 | $this->debug->displayError('Invalid table name, table name in empty.', false); |
|
| 901 | ||
| 902 | return false; |
|
| 903 | } |
|
| 904 | ||
| 905 | if (\is_string($where)) { |
|
| 906 | $WHERE = $this->escape($where, false); |
|
| 907 | } elseif (\is_array($where)) { |
|
| 908 | $WHERE = $this->_parseArrayPair($where, 'AND'); |
|
| 909 | } else { |
|
| 910 | $WHERE = ''; |
|
| 911 | } |
|
| 912 | ||
| 913 | if ($databaseName) { |
|
| 914 | $databaseName = $this->quote_string(\trim($databaseName)) . '.'; |
|
| 915 | } |
|
| 916 | ||
| 917 | $sql = 'DELETE FROM ' . $databaseName . $this->quote_string($table) . " WHERE (${WHERE})"; |
|
| 918 | ||
| 919 | $return = $this->query($sql); |
|
| 920 | ||
| 921 | \assert(\is_int($return) || $return === false); |
|
| 922 | ||
| 923 | return $return; |
|
| 924 | } |
|
| 925 | ||
| 926 | /** |
|
| 927 | * Ends a transaction and commits if no errors, then ends autocommit. |
|
| @@ 2285-2314 (lines=30) @@ | ||
| 2282 | * @return false|Result |
|
| 2283 | * <p>false on error</p> |
|
| 2284 | */ |
|
| 2285 | public function select(string $table, $where = '1=1', string $databaseName = null) |
|
| 2286 | { |
|
| 2287 | // init |
|
| 2288 | $table = \trim($table); |
|
| 2289 | ||
| 2290 | if ($table === '') { |
|
| 2291 | $this->debug->displayError('Invalid table name, table name in empty.', false); |
|
| 2292 | ||
| 2293 | return false; |
|
| 2294 | } |
|
| 2295 | ||
| 2296 | if (\is_string($where)) { |
|
| 2297 | $WHERE = $this->escape($where, false); |
|
| 2298 | } elseif (\is_array($where)) { |
|
| 2299 | $WHERE = $this->_parseArrayPair($where, 'AND'); |
|
| 2300 | } else { |
|
| 2301 | $WHERE = ''; |
|
| 2302 | } |
|
| 2303 | ||
| 2304 | if ($databaseName) { |
|
| 2305 | $databaseName = $this->quote_string(\trim($databaseName)) . '.'; |
|
| 2306 | } |
|
| 2307 | ||
| 2308 | $sql = 'SELECT * FROM ' . $databaseName . $this->quote_string($table) . " WHERE (${WHERE})"; |
|
| 2309 | ||
| 2310 | $return = $this->query($sql); |
|
| 2311 | \assert($return instanceof Result || $return === false); |
|
| 2312 | ||
| 2313 | return $return; |
|
| 2314 | } |
|
| 2315 | ||
| 2316 | /** |
|
| 2317 | * Selects a different database than the one specified on construction. |
|