diff --git a/src/Illuminate/Database/MySqlConnection.php b/src/Illuminate/Database/MySqlConnection.php index 1e7fff2f5313..01def05d0621 100755 --- a/src/Illuminate/Database/MySqlConnection.php +++ b/src/Illuminate/Database/MySqlConnection.php @@ -77,7 +77,7 @@ public function bindValues($statement, $bindings) foreach ($bindings as $key => $value) { $statement->bindValue( is_string($key) ? $key : $key + 1, $value, - is_int($value) || is_float($value) ? PDO::PARAM_INT : PDO::PARAM_STR + is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR ); } } diff --git a/tests/Database/DatabaseMySqlConnectionTest.php b/tests/Database/DatabaseMySqlConnectionTest.php new file mode 100644 index 000000000000..8b7aab58c975 --- /dev/null +++ b/tests/Database/DatabaseMySqlConnectionTest.php @@ -0,0 +1,62 @@ +createMock(PDOStatement::class); + $statement + ->expects($this->at(0)) + ->method('bindValue') + ->with(1, 0.5, PDO::PARAM_STR); + + $connection->bindValues($statement, [0 => 0.5]); + } + + public function testBindStringValue() + { + $connection = new MySqlConnection( + function () { + throw new \UnexpectedValueException('Not expecting to really connect to database'); + } + ); + + $statement = $this->createMock(PDOStatement::class); + $statement + ->expects($this->at(0)) + ->method('bindValue') + ->with(1, 'test', PDO::PARAM_STR); + + $connection->bindValues($statement, [0 => 'test']); + } + + public function testBindIntegerValue() + { + $connection = new MySqlConnection( + function () { + throw new \UnexpectedValueException('Not expecting to really connect to database'); + } + ); + + $statement = $this->createMock(PDOStatement::class); + $statement + ->expects($this->at(0)) + ->method('bindValue') + ->with(1, 27, PDO::PARAM_INT); + + $connection->bindValues($statement, [0 => 27]); + } +}