Skip to content

Commit

Permalink
Release version 1.9.9
Browse files Browse the repository at this point in the history
  • Loading branch information
FaaPz committed May 29, 2016
1 parent 5f766ca commit 2c3cf65
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
### Changelog

##### v1.9.9
+ Added ability to insert associative arrays (#35)
+ Updated `Database` class with:
- Renamed `$columns` argument in `insert()` method
+ Updated `StatementContainer` class with:
- Added `isAssociative()` method
- Fixed `getPlaceholders()` method

> Proposed by [Raistlfiren](https://github.com/Raistlfiren). Thanks!
##### v1.9.8
+ Updated `SelectStatement` class with:
- Fixed `getColumns()` method
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "slim/pdo",
"description": "PDO database library for Slim Framework",
"version": "1.9.8",
"version": "1.9.9",
"type": "library",
"keywords": ["pdo", "database", "slim", "framework"],
"homepage": "https://github.com/FaaPz/Slim-PDO",
Expand Down
6 changes: 3 additions & 3 deletions src/PDO/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public function select(array $columns = array('*'))
}

/**
* @param array $columns
* @param array $columnsOrPairs
*
* @return InsertStatement
*/
public function insert(array $columns = array())
public function insert(array $columnsOrPairs = array())
{
return new InsertStatement($this, $columns);
return new InsertStatement($this, $columnsOrPairs);
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/PDO/Statement/InsertStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ class InsertStatement extends StatementContainer
* Constructor.
*
* @param Database $dbh
* @param array $columns
* @param array $columnsOrPairs
*/
public function __construct(Database $dbh, array $columns)
public function __construct(Database $dbh, array $columnsOrPairs)
{
parent::__construct($dbh);

$this->columns($columns);
if ($this->isAssociative($columnsOrPairs)) {
$this->columns(array_keys($columnsOrPairs));
$this->values(array_values($columnsOrPairs));
} else {
$this->columns($columnsOrPairs);
}
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/PDO/Statement/StatementContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ protected function getPlaceholders()
{
$placeholders = $this->placeholders;

unset($this->placeholders);
reset($this->placeholders);

return '( '.implode(' , ', $placeholders).' )';
}
Expand All @@ -472,6 +472,16 @@ protected function setPlaceholders(array $values)
}
}

/**
* @param array $array
*
* @return bool
*/
protected function isAssociative(array $array)
{
return array_keys($array) !== range(0, count($array) - 1);
}

/**
* @return \PDOStatement
*/
Expand Down

0 comments on commit 2c3cf65

Please sign in to comment.