-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
2,424 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# --------------------------- | ||
# --- OSX Generated Files --- | ||
# --------------------------- | ||
|
||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# --- Icon Must End With Two \r --- | ||
Icon | ||
|
||
|
||
# --- Thumbnails --- | ||
._* | ||
|
||
# --- Files That Might Appear On External Disk --- | ||
.Spotlight-V100 | ||
.Trashes | ||
|
||
# --- Directories Potentially Created On Remote AFP Share --- | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
# --------------------------- | ||
# --- WIN Generated Files --- | ||
# --------------------------- | ||
|
||
# --- Windows Image File Caches --- | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# --- Folder Config File --- | ||
Desktop.ini | ||
|
||
# --- Recycle Bin Used On File Shares --- | ||
$RECYCLE.BIN/ | ||
|
||
# --- Windows Installer Files --- | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# --------------------------- | ||
# ---- Development Files ---- | ||
# --------------------------- | ||
|
||
composer.lock | ||
composer.phar | ||
vendor/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
### Changelog | ||
|
||
##### v1.6.1 | ||
+ Updated documentation, see [docs](https://github.com/FaaPz/Slim-PDO/blob/master/docs) directory | ||
+ Updated query builder with: | ||
- Added `havingCount()` method | ||
- Added `havingMax()` method | ||
- Added `havingMin()` method | ||
- Added `havingAvg()` method | ||
- Added `havingSum()` method | ||
|
||
##### v1.6.0 | ||
+ Added documentation, see [docs](https://github.com/FaaPz/Slim-PDO/blob/master/docs) directory | ||
+ Removed `AggregateClause` class (stupid mistake, aggregates are not clauses) | ||
+ Updated query builder with: | ||
- Added `whereLike()` method | ||
- Added `orWhereLike()` method | ||
- Added `whereNotLike()` method | ||
- Added `orWhereNotLike()` method | ||
+ Updated `SelectStatement` class with: | ||
- Added aggregate methods `count()`, `distinctCount()`, `max()`, `min()`, `avg()` and `sum()` | ||
|
||
##### v1.5.0 | ||
+ Updated query builder with: | ||
- Added `having()` method | ||
- Added `orHaving()` method | ||
- Added `distinct()` method | ||
- Added `count()` method | ||
- Added `distinctCount()` method | ||
- Added `max()` method | ||
- Added `min()` method | ||
- Added `avg()` method | ||
- Added `sum()` method | ||
|
||
##### v1.4.0 | ||
+ Updated query builder with: | ||
- Added `whereBetween()` method | ||
- Added `orWhereBetween()` method | ||
- Added `whereNotBetween()` method | ||
- Added `orWhereNotBetween()` method | ||
- Added `whereIn()` method | ||
- Added `orWhereIn()` method | ||
- Added `whereNotIn()` method | ||
- Added `orWhereNotIn()` method | ||
- Added `whereNull()` method | ||
- Added `orWhereNull()` method | ||
- Added `whereNotNull()` method | ||
- Added `orWhereNotNull()` method | ||
|
||
##### v1.3.0 | ||
+ Updated query builder with: | ||
- Added `where()` method | ||
- Added `orWhere()` method | ||
- Added `join()` method | ||
- Added `leftJoin()` method | ||
- Added `rightJoin()` method | ||
- Added `fullJoin()` method | ||
|
||
##### v1.2.0 | ||
+ Updated query builder with: | ||
- Added `groupBy()` method | ||
- Added `orderBy()` method | ||
- Added `limit()` method | ||
- Added `offset()` method | ||
|
||
##### v1.1.0 | ||
+ Added query builder | ||
|
||
##### v1.0.0 | ||
+ First release version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,84 @@ | ||
# Slim-PDO | ||
|
||
PDO database library for Slim Framework | ||
|
||
### Installation | ||
|
||
Use [Composer](https://getcomposer.org/) | ||
|
||
```json | ||
"require": { | ||
"slim/pdo": "~1.7" | ||
} | ||
``` | ||
|
||
### Usage | ||
|
||
Simple example selecting all data from `users` table. | ||
|
||
```php | ||
require_once('vendor/autoload.php'); | ||
|
||
$dsn = 'mysql:host=your_db_host;dbname=your_db_name;charset=utf8'; | ||
$usr = 'your_db_username'; | ||
$pwd = 'your_db_password'; | ||
|
||
$pdo = new \Slim\PDO\Database( $dsn , $usr , $pwd ); | ||
|
||
$qry = $pdo->prepare("SELECT * FROM users"); | ||
$qry->execute(); | ||
|
||
try | ||
{ | ||
var_dump( $qry->fetchAll() ); | ||
} | ||
catch( \PDOException $e ) | ||
{ | ||
exit( $e->getMessage() ); | ||
} | ||
``` | ||
|
||
Examples selecting, inserting, updating and deleting data from or into `users` table. | ||
|
||
```php | ||
// SELECT * FROM users WHERE id = ? | ||
$selectStatement = $pdo->select() | ||
->from('users') | ||
->where('id', '=', 1234); | ||
|
||
$stmt = $selectStatement->execute(); | ||
$data = $stmt->fetchAll(); | ||
|
||
// INSERT INTO users ( id , usr , pwd ) VALUES ( ? , ? , ? ) | ||
$insertStatement = $pdo->insert(array('id', 'usr', 'pwd')) | ||
->into('users') | ||
->values(array(1234, 'your_username', 'your_password')); | ||
|
||
$insertId = $insertStatement->execute(); | ||
|
||
// UPDATE users SET pwd = ? WHERE id = ? | ||
$updateStatement = $pdo->update(array('pwd' => 'your_new_password')) | ||
->table('users') | ||
->where('id', '=', 1234); | ||
|
||
$affectedRows = $updateStatement->execute(); | ||
|
||
// DELETE FROM users WHERE id = ? | ||
$deleteStatement = $pdo->delete() | ||
->from('users') | ||
->where('id', '=', 1234); | ||
|
||
$affectedRows = $deleteStatement->execute(); | ||
``` | ||
|
||
### Documentation (WIP) | ||
|
||
See [DOCUMENTATION](https://github.com/FaaPz/Slim-PDO/blob/master/docs/README.md) | ||
|
||
### Changelog | ||
|
||
See [CHANGELOG](https://github.com/FaaPz/Slim-PDO/blob/master/CHANGELOG.md) | ||
|
||
### License | ||
|
||
See [LICENSE](https://github.com/FaaPz/Slim-PDO/blob/master/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "slim/pdo", | ||
"description": "PDO database library for Slim Framework", | ||
"version": "1.7.0", | ||
"type": "library", | ||
"keywords": ["pdo", "database", "slim", "framework"], | ||
"homepage": "https://github.com/FaaPz/Slim-PDO", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Fabian de Laender", | ||
"email": "[email protected]", | ||
"homepage": "http://faapz.nl", | ||
"role": "Developer" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/FaaPz/Slim-PDO/issues" | ||
}, | ||
"require": { | ||
"php": ">=5.3.0", | ||
"ext-pdo": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Slim\\PDO\\": "src/PDO/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
### Aggregates | ||
|
||
##### Methods | ||
|
||
+ `count()` | ||
+ `distinctCount()` | ||
+ `max()` | ||
+ `min()` | ||
+ `avg()` | ||
+ `sum()` | ||
|
||
> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. | ||
##### Examples | ||
|
||
```php | ||
// ... COUNT( * ) | ||
$selectStatement->count(); | ||
|
||
// ... COUNT( votes ) AS all_votes | ||
$selectStatement->count('votes', 'all_votes'); | ||
|
||
// ... COUNT( DISTINCT customer_id ) | ||
$selectStatement->distinctCount('customer_id'); | ||
|
||
// ... MIN|MAX( salary ) , AVG( price ) , SUM( votes ) | ||
$selectStatement->min('salary'); | ||
$selectStatement->max('salary'); | ||
$selectStatement->avg('price'); | ||
$selectStatement->sum('votes'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### GROUP BY clause | ||
|
||
##### Methods | ||
|
||
+ `groupBy()` | ||
|
||
> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. | ||
##### Examples of grouping | ||
|
||
```php | ||
// ... GROUP BY f_name | ||
$selectStatement->groupBy('f_name'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
### HAVING clause | ||
|
||
##### Methods | ||
|
||
+ `having()` | ||
+ `orHaving()` | ||
+ `havingCount()` | ||
+ `havingMax()` | ||
+ `havingMin()` | ||
+ `havingAvg()` | ||
+ `havingSum()` | ||
|
||
> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. | ||
##### Examples | ||
|
||
```php | ||
// ... HAVING MIN( price ) > ? OR MAX( price ) < ? | ||
$selectStatement->having('MIN( price )', '>', 125)->orHaving('MAX( price )', '<', 250); | ||
|
||
// ... HAVING COUNT( * ) > ? | ||
$selectStatement->havingCount('*', '>', 1234); | ||
|
||
// ... HAVING MIN|MAX( salary ) > ? | ||
$selectStatement->havingMin('salary', '>', 25000); | ||
$selectStatement->havingMax('salary', '<', 50000); | ||
|
||
// ... HAVING AVG( price ) < ? | ||
$selectStatement->havingAvg('price', '<', 12.5); | ||
|
||
// ... HAVING SUM( votes ) > ? | ||
$selectStatement->havingSum('votes', '>', 25); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
### JOIN clause | ||
|
||
##### Methods | ||
|
||
+ `join()` | ||
+ `leftJoin()` | ||
+ `rightJoin()` | ||
+ `fullJoin()` | ||
|
||
> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. | ||
##### Examples | ||
|
||
```php | ||
// ... INNER JOIN orders ON customers.id = orders.customer_id | ||
$selectStatement->join('orders', 'customers.id', '=', 'orders.customer_id'); | ||
$selectStatement->join('orders', 'customers.id', '=', 'orders.customer_id', 'INNER'); | ||
|
||
// ... LEFT OUTER JOIN orders ON customers.id = orders.customer_id | ||
$selectStatement->leftJoin('orders', 'customers.id', '=', 'orders.customer_id'); | ||
|
||
// ... RIGHT OUTER JOIN orders ON customers.id = orders.customer_id | ||
$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'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### LIMIT clause | ||
|
||
##### Methods | ||
|
||
+ `limit()` | ||
|
||
> 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 of limiting | ||
|
||
```php | ||
// ... LIMIT 10 | ||
$statement->limit(10); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### OFFSET clause | ||
|
||
##### Methods | ||
|
||
+ `offset()` | ||
|
||
> Used only in [SELECT](https://github.com/FaaPz/Slim-PDO/blob/master/docs/Statement/SELECT.md) statements. | ||
##### Examples of offsetting | ||
|
||
```php | ||
// ... OFFSET 20 | ||
$selectStatement->offset(20); | ||
``` |
Oops, something went wrong.