diff --git a/CHANGELOG.md b/CHANGELOG.md index c5aff5d..2446dc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ### Changelog +##### v1.9.4 ++ Revised documentation (WIP) ++ Updated `InsertStatement` class with: + - Fixed `execute()` method + ##### v1.9.3 + Updated `InsertStatement` class with: - Added `$insertId` argument in `execute()` method @@ -53,4 +58,4 @@ + Removed old changelog notes ##### v1.7.0 -+ Revised release version \ No newline at end of file ++ Revised release version diff --git a/LICENSE b/LICENSE index 185a313..c970b51 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Fabian de Laender +Copyright (c) 2015-2016 Fabian de Laender Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index 901b804..8461b1b 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ $insertStatement = $pdo->insert(array('id', 'usr', 'pwd')) ->into('users') ->values(array(1234, 'your_username', 'your_password')); -$insertId = $insertStatement->execute(); +$insertId = $insertStatement->execute(false); // UPDATE users SET pwd = ? WHERE id = ? $updateStatement = $pdo->update(array('pwd' => 'your_new_password')) @@ -70,4 +70,4 @@ See [CHANGELOG](https://github.com/FaaPz/Slim-PDO/blob/master/CHANGELOG.md) ### License -See [LICENSE](https://github.com/FaaPz/Slim-PDO/blob/master/LICENSE) \ No newline at end of file +See [LICENSE](https://github.com/FaaPz/Slim-PDO/blob/master/LICENSE) diff --git a/composer.json b/composer.json index c577a9a..a57284f 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "slim/pdo", "description": "PDO database library for Slim Framework", - "version": "1.9.3", + "version": "1.9.4", "type": "library", "keywords": ["pdo", "database", "slim", "framework"], "homepage": "https://github.com/FaaPz/Slim-PDO", diff --git a/docs/AGGREGATES.md b/docs/AGGREGATES.md index 28f2a33..1591d09 100644 --- a/docs/AGGREGATES.md +++ b/docs/AGGREGATES.md @@ -1,17 +1,53 @@ -### Aggregates +# Aggregates -##### Methods +> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. -+ `count()` -+ `distinctCount()` -+ `max()` -+ `min()` -+ `avg()` -+ `sum()` +### Methods -> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. +##### `count($column = '*', $as = null, $distinct = false)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | `'*'` | ... +`$as` | *string* | `null` | ... +`$distinct` | *bool* | `false` | ... + +##### `distinctCount($column = '*', $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | `'*'` | ... +`$as` | *string* | `null` | ... + +##### `max($column, $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$as` | *string* | `null` | ... + +##### `min($column, $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$as` | *string* | `null` | ... + +##### `avg($column, $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$as` | *string* | `null` | ... + +##### `sum($column, $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$as` | *string* | `null` | ... -##### Examples +### Examples ```php // ... COUNT( * ) @@ -28,4 +64,4 @@ $selectStatement->min('salary'); $selectStatement->max('salary'); $selectStatement->avg('price'); $selectStatement->sum('votes'); -``` \ No newline at end of file +``` diff --git a/docs/Clause/GROUP_BY.md b/docs/Clause/GROUP_BY.md index 872551b..b51de1a 100644 --- a/docs/Clause/GROUP_BY.md +++ b/docs/Clause/GROUP_BY.md @@ -1,14 +1,18 @@ -### GROUP BY clause +# GROUP BY clause -##### Methods +> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. -+ `groupBy()` +### Methods -> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. +##### `groupBy($statement)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$statement` | *string* | required | ... -##### Examples of grouping +### Examples ```php // ... GROUP BY f_name $selectStatement->groupBy('f_name'); -``` \ No newline at end of file +``` diff --git a/docs/Clause/HAVING.md b/docs/Clause/HAVING.md index f400d8e..9ef7686 100644 --- a/docs/Clause/HAVING.md +++ b/docs/Clause/HAVING.md @@ -1,18 +1,60 @@ -### HAVING clause +# HAVING clause -##### Methods +> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. -+ `having()` -+ `orHaving()` -+ `havingCount()` -+ `havingMax()` -+ `havingMin()` -+ `havingAvg()` -+ `havingSum()` +### Methods -> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. +##### `having($column, $operator = null, $rule = 'AND')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$rule` | *string* | `'AND'` | ... + +##### `orHaving($column, $operator = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... + +##### `havingCount($column, $operator = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... + +##### `havingMax($column, $operator = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... + +##### `havingMin($column, $operator = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... + +##### `havingAvg($column, $operator = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... + +##### `havingSum($column, $operator = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... -##### Examples +### Examples ```php // ... HAVING MIN( price ) > ? OR MAX( price ) < ? @@ -30,4 +72,4 @@ $selectStatement->havingAvg('price', '<', 12.5); // ... HAVING SUM( votes ) > ? $selectStatement->havingSum('votes', '>', 25); -``` \ No newline at end of file +``` diff --git a/docs/Clause/JOIN.md b/docs/Clause/JOIN.md index 189dcde..eb9455e 100644 --- a/docs/Clause/JOIN.md +++ b/docs/Clause/JOIN.md @@ -1,15 +1,47 @@ -### JOIN clause +# JOIN clause -##### Methods +> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. -+ `join()` -+ `leftJoin()` -+ `rightJoin()` -+ `fullJoin()` +### Methods -> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. +##### `join($table, $first, $operator = null, $second = null, $type = 'INNER')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... +`$first` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$second` | *string* | `null` | ... +`$type` | *string* | `'INNER'` | ... + +##### `leftJoin($table, $first, $operator = null, $second = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... +`$first` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$second` | *string* | `null` | ... + +##### `rightJoin($table, $first, $operator = null, $second = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... +`$first` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$second` | *string* | `null` | ... + +##### `fullJoin($table, $first, $operator = null, $second = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... +`$first` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$second` | *string* | `null` | ... -##### Examples +### Examples ```php // ... INNER JOIN orders ON customers.id = orders.customer_id @@ -24,4 +56,4 @@ $selectStatement->rightJoin('orders', 'customers.id', '=', 'orders.customer_id') // ... FULL OUTER JOIN orders ON customers.id = orders.customer_id $selectStatement->fullJoin('orders', 'customers.id', '=', 'orders.customer_id'); -``` \ No newline at end of file +``` diff --git a/docs/Clause/LIMIT.md b/docs/Clause/LIMIT.md index d75bb22..7b23353 100644 --- a/docs/Clause/LIMIT.md +++ b/docs/Clause/LIMIT.md @@ -1,12 +1,17 @@ -### LIMIT clause +# LIMIT clause -##### Methods +> Used in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/DELETE.md) statements. -+ `limit()` +### Methods -> Used in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/DELETE.md) statements. +##### `limit($number, $end = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$number` | *int* | required | ... +`$end` | *int* | `null` | ... -##### Examples of limiting +### Examples ```php // ... LIMIT 10 @@ -14,4 +19,4 @@ $statement->limit(10); // ... LIMIT 10 , 30 $statement->limit(10, 30); -``` \ No newline at end of file +``` diff --git a/docs/Clause/OFFSET.md b/docs/Clause/OFFSET.md index b1ea5f8..f846d6a 100644 --- a/docs/Clause/OFFSET.md +++ b/docs/Clause/OFFSET.md @@ -1,14 +1,18 @@ -### OFFSET clause +# OFFSET clause -##### Methods +> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. -+ `offset()` +### Methods -> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. +##### `offset($number)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$number` | *int* | required | ... -##### Examples of offsetting +### Examples ```php // ... OFFSET 20 $selectStatement->offset(20); -``` \ No newline at end of file +``` diff --git a/docs/Clause/ORDER_BY.md b/docs/Clause/ORDER_BY.md index 1fa42be..bd13b96 100644 --- a/docs/Clause/ORDER_BY.md +++ b/docs/Clause/ORDER_BY.md @@ -1,12 +1,17 @@ -### ORDER BY clause +# ORDER BY clause -##### Methods +> Used in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/DELETE.md) statements. -+ `orderBy()` +### Methods -> Used in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/DELETE.md) statements. +##### `orderBy($statement, $order = 'ASC')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$statement` | *string* | required | ... +`$order` | *string* | `'ASC'` | ... -##### Examples of ordering +### Examples ```php // ... ORDER BY l_name ASC @@ -15,4 +20,4 @@ $statement->orderBy('l_name', 'ASC'); // ... ORDER BY l_name DESC $statement->orderBy('l_name', 'DESC'); -``` \ No newline at end of file +``` diff --git a/docs/Clause/WHERE.md b/docs/Clause/WHERE.md index a41400f..6e4867e 100644 --- a/docs/Clause/WHERE.md +++ b/docs/Clause/WHERE.md @@ -1,30 +1,145 @@ -### WHERE clause - -##### Methods - -+ `where()` -+ `orWhere()` -+ `whereBetween()` -+ `orWhereBetween()` -+ `whereNotBetween()` -+ `orWhereNotBetween()` -+ `whereIn()` -+ `orWhereIn()` -+ `whereNotIn()` -+ `orWhereNotIn()` -+ `whereLike()` -+ `orWhereLike()` -+ `whereNotLike()` -+ `orWhereNotLike()` -+ `whereNull()` -+ `orWhereNull()` -+ `whereNotNull()` -+ `orWhereNotNull()` -+ `whereMany()` +# WHERE clause > Used in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md), [UPDATE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/UPDATE.md) and [DELETE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/DELETE.md) statements. -##### Examples +### Methods + +##### `where($column, $operator = null, $rule = 'AND')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$rule` | *string* | `'AND'` | ... + +##### `orWhere($column, $operator = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... + +##### `whereBetween($column, $rule = 'AND', $not = false)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$rule` | *string* | `'AND'` | ... +`$not` | *bool* | `false` | ... + +##### `orWhereBetween($column)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... + +##### `whereNotBetween($column, $rule = 'AND')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$rule` | *string* | `'AND'` | ... + +##### `orWhereNotBetween($column)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... + +##### `whereIn($column, $placeholders, $rule = 'AND', $not = false)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$placeholders` | *mixed* | required | ... +`$rule` | *string* | `'AND'` | ... +`$not` | *bool* | `false` | ... + +##### `orWhereIn($column, $placeholders)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$placeholders` | *mixed* | required | ... + +##### `whereNotIn($column, $placeholders, $rule = 'AND')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$placeholders` | *mixed* | required | ... +`$rule` | *string* | `'AND'` | ... + +##### `orWhereNotIn($column, $placeholders)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$placeholders` | *mixed* | required | ... + +##### `whereLike($column, $rule = 'AND', $not = false)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$rule` | *string* | `'AND'` | ... +`$not` | *bool* | `false` | ... + +##### `orWhereLike($column)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... + +##### `whereNotLike($column, $rule = 'AND')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$rule` | *string* | `'AND'` | ... + +##### `orWhereNotLike($column)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... + +##### `whereNull($column, $rule = 'AND', $not = false)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$rule` | *string* | `'AND'` | ... +`$not` | *bool* | `false` | ... + +##### `orWhereNull($column)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... + +##### `whereNotNull($column, $rule = 'AND')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$rule` | *string* | `'AND'` | ... + +##### `orWhereNotNull($column)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... + +##### `whereMany($columns, $operator = null, $rule = 'AND')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$columns` | *mixed* | required | ... +`$operator` | *string* | `null` | ... +`$rule` | *string* | `'AND'` | ... + +### Examples ```php // ... WHERE usr = ? OR f_name = ? diff --git a/docs/README.md b/docs/README.md index cfa7c5d..a41b611 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,17 +1,15 @@ -### Documentation +# Documentation -##### Important -*Before reading through the following commands and methods, please be aware that it is possible - to use raw PDO stuff, like ``fetch()``,``fetchAll()``, ``execute()`` and the others whenever you feel you need to.* +> **IMPORTANT!** Before reading through the following commands and methods, please be aware that it is possible to use raw PDO stuff, like `fetch()`, `fetchAll()`, `execute()` and the others whenever you feel you need to. -##### Statements +### Statements + [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) + [INSERT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/INSERT.md) + [UPDATE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/UPDATE.md) + [DELETE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/DELETE.md) -##### Clauses +### Clauses + [JOIN](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/JOIN.md) + [WHERE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/WHERE.md) @@ -21,6 +19,6 @@ + [LIMIT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/LIMIT.md) + [OFFSET](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/OFFSET.md) -##### Functions +### Functions + [AGGREGATES](https://github.com/FaaPz/Slim-PDO/blob/master/docs/AGGREGATES.md) diff --git a/docs/Statement/DELETE.md b/docs/Statement/DELETE.md index b1174df..1647d6f 100644 --- a/docs/Statement/DELETE.md +++ b/docs/Statement/DELETE.md @@ -1,16 +1,22 @@ -### DELETE statement +# DELETE statement -##### Methods +### Methods -+ `from()` +##### `from($table)` -##### Clauses +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... + +##### `execute()` + +### Clauses + [WHERE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/WHERE.md) + [ORDER BY](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/ORDER_BY.md) + [LIMIT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/LIMIT.md) -##### Examples +### Examples ```php // DELETE FROM users WHERE id = ? @@ -19,4 +25,4 @@ $deleteStatement = $slimPdo->delete() ->where('id', '=', 1234); $affectedRows = $deleteStatement->execute(); -``` \ No newline at end of file +``` diff --git a/docs/Statement/INSERT.md b/docs/Statement/INSERT.md index 447a6fe..7a216b5 100644 --- a/docs/Statement/INSERT.md +++ b/docs/Statement/INSERT.md @@ -1,12 +1,32 @@ -### INSERT statement +# INSERT statement -##### Methods +### Methods -+ `into()` -+ `columns()` -+ `values()` +##### `into($table)` -##### Examples +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... + +##### `columns(array $columns)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$columns` | *array* | required | ... + +##### `values(array $values)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$values` | *array* | required | ... + +##### `execute($insertId = true)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$insertId` | *bool* | `true` | ... + +### Examples ```php // INSERT INTO users ( id , usr , pwd ) VALUES ( ? , ? , ? ) @@ -20,5 +40,5 @@ $insertStatement = $slimPdo->insert(array('id')) ->columns(array('usr', 'pwd')) ->values(array(1234, 'your_username', 'your_password')); -$insertId = $insertStatement->execute(); -``` \ No newline at end of file +$insertId = $insertStatement->execute(false); +``` diff --git a/docs/Statement/SELECT.md b/docs/Statement/SELECT.md index 190d149..c8d5d81 100644 --- a/docs/Statement/SELECT.md +++ b/docs/Statement/SELECT.md @@ -1,35 +1,171 @@ -### SELECT statement - -##### Methods - -+ `distinct()` -+ `from()` -+ `join()` -+ `leftJoin()` -+ `rightJoin()` -+ `fullJoin()` -+ `groupBy()` -+ `having()` -+ `orHaving()` -+ `havingCount()` -+ `havingMax()` -+ `havingMin()` -+ `havingAvg()` -+ `havingSum()` -+ `offset()` - -##### Aggregate methods - -+ `count` -+ `distinctCount()` -+ `max()` -+ `min()` -+ `avg()` -+ `sum()` - -> Documentation? Click [here](https://github.com/FaaPz/Slim-PDO/blob/master/docs/AGGREGATES.md)! - -##### Clauses +# SELECT statement + +### Methods + +##### `distinct()` + +##### `from($table)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... + +##### `join($table, $first, $operator = null, $second = null, $type = 'INNER')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... +`$first` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$second` | *string* | `null` | ... +`$type` | *string* | `'INNER'` | ... + +##### `leftJoin($table, $first, $operator = null, $second = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... +`$first` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$second` | *string* | `null` | ... + +##### `rightJoin($table, $first, $operator = null, $second = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... +`$first` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$second` | *string* | `null` | ... + +##### `fullJoin($table, $first, $operator = null, $second = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... +`$first` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$second` | *string* | `null` | ... + +##### `groupBy($statement)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$statement` | *string* | required | ... + +##### `having($column, $operator = null, $value = null, $rule = 'AND')` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$value` | *string* | `null` | ... +`$rule` | *string* | `'AND'` | ... + +##### `orHaving($column, $operator = null, $value = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$value` | *string* | `null` | ... + +##### `havingCount($column, $operator = null, $value = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$value` | *string* | `null` | ... + +##### `havingMax($column, $operator = null, $value = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$value` | *string* | `null` | ... + +##### `havingMin($column, $operator = null, $value = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$value` | *string* | `null` | ... + +##### `havingAvg($column, $operator = null, $value = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$value` | *string* | `null` | ... + +##### `havingSum($column, $operator = null, $value = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$operator` | *string* | `null` | ... +`$value` | *string* | `null` | ... + +##### `offset($number)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$number` | *int* | required | ... + +##### `execute()` + +### Aggregate methods + +##### `count($column = '*', $as = null, $distinct = false)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | `'*'` | ... +`$as` | *string* | `null` | ... +`$distinct` | *bool* | `false` | ... + +##### `distinctCount($column = '*', $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | `'*'` | ... +`$as` | *string* | `null` | ... + +##### `max($column, $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$as` | *string* | `null` | ... + +##### `min($column, $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$as` | *string* | `null` | ... + +##### `avg($column, $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$as` | *string* | `null` | ... + +##### `sum($column, $as = null)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$column` | *string* | required | ... +`$as` | *string* | `null` | ... + +> Example code? Click [here](https://github.com/FaaPz/Slim-PDO/blob/master/docs/AGGREGATES.md)! + +### Clauses + [JOIN](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/JOIN.md) + [WHERE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/WHERE.md) @@ -39,7 +175,7 @@ + [LIMIT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/LIMIT.md) + [OFFSET](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/OFFSET.md) -##### Examples +### Examples ```php // SELECT * FROM users WHERE id = ? @@ -49,4 +185,4 @@ $selectStatement = $slimPdo->select() $stmt = $selectStatement->execute(); $data = $stmt->fetch(); -``` \ No newline at end of file +``` diff --git a/docs/Statement/UPDATE.md b/docs/Statement/UPDATE.md index aea8e30..9aed0c1 100644 --- a/docs/Statement/UPDATE.md +++ b/docs/Statement/UPDATE.md @@ -1,17 +1,28 @@ -### UPDATE statement +# UPDATE statement -##### Methods +### Methods -+ `table()` -+ `set()` +##### `table($table)` -##### Clauses +Parameter | Type | Default | Description +--- | --- | --- | --- +`$table` | *string* | required | ... + +##### `set(array $pairs)` + +Parameter | Type | Default | Description +--- | --- | --- | --- +`$pairs` | *array* | required | ... + +##### `execute()` + +### Clauses + [WHERE](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/WHERE.md) + [ORDER BY](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/ORDER_BY.md) + [LIMIT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Clause/LIMIT.md) -##### Examples +### Examples ```php // UPDATE users SET pwd = ? WHERE id = ? @@ -26,4 +37,4 @@ $updateStatement = $slimPdo->update(array('usr' => 'your_new_username')) ->where('id', '=', 1234); $affectedRows = $updateStatement->execute(); -``` \ No newline at end of file +``` diff --git a/src/PDO/Statement/InsertStatement.php b/src/PDO/Statement/InsertStatement.php index 0c5ceeb..0004eb5 100644 --- a/src/PDO/Statement/InsertStatement.php +++ b/src/PDO/Statement/InsertStatement.php @@ -100,8 +100,9 @@ public function execute($insertId = true) if (!$insertId) { return parent::execute(); } + parent::execute(); - + return $this->dbh->lastInsertId(); }