PDOWrapper::delete PHP Метод

delete() публичный Метод

- deletes rows from a table based on the parameters
public delete ( $table, $params = [] ) : boolean
Результат boolean - associate representing the fetched table row, false on failure
    public function delete($table, $params = array())
    {
        // building query string
        $sql_str = "DELETE FROM {$table}";
        // append WHERE if necessary
        $sql_str .= count($params) > 0 ? ' WHERE ' : '';
        $add_and = false;
        // add each clause using parameter array
        foreach ($params as $key => $val) {
            // only add AND after the first clause item has been appended
            if ($add_and) {
                $sql_str .= ' AND ';
            } else {
                $add_and = true;
            }
            // append clause item
            $sql_str .= "{$key} = :{$key}";
        }
        // now we attempt to retrieve the row using the sql string
        try {
            $pstmt = $this->getMaster()->prepare($sql_str);
            // bind each parameter in the array
            foreach ($params as $key => $val) {
                $pstmt->bindValue(':' . $key, $val);
            }
            // execute the delete query
            $successful_delete = $pstmt->execute();
            // if we were successful, return the amount of rows updated, otherwise return false
            return $successful_delete == true ? $pstmt->rowCount() : false;
        } catch (PDOException $e) {
            if (self::$LOG_ERRORS == true) {
                error_log('DATABASE WRAPPER::' . print_r($e, true));
            }
            $this->pdo_exception = $e;
            return false;
        } catch (Exception $e) {
            if (self::$LOG_ERRORS == true) {
                error_log('DATABASE WRAPPER::' . print_r($e, true));
            }
            $this->pdo_exception = $e;
            return false;
        }
    }