Skip to content

Commit

Permalink
Fix issue with non-emulated prepared statements on MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Apr 20, 2021
1 parent 9998520 commit 5ebcd63
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
emulate-prepares:
- "ON"
- "OFF"

services:
mysql:
Expand Down Expand Up @@ -66,6 +69,7 @@ jobs:
run: vendor/bin/phpunit
env:
ENGINE: PDO_MYSQL
EMULATE_PREPARES: ${{ matrix.emulate-prepares }}
if: ${{ matrix.php-version != '8.0' }}

- name: Run PHPUnit with coverage
Expand All @@ -74,6 +78,7 @@ jobs:
vendor/bin/phpunit --coverage-clover build/logs/clover.xml
env:
ENGINE: PDO_MYSQL
EMULATE_PREPARES: ${{ matrix.emulate-prepares }}
if: ${{ matrix.php-version == '8.0' }}

- name: Upload coverage report to Coveralls
Expand All @@ -90,6 +95,9 @@ jobs:
matrix:
php-version:
- "8.0"
emulate-prepares:
- "ON"
- "OFF"

services:
mariadb:
Expand Down Expand Up @@ -121,6 +129,7 @@ jobs:
vendor/bin/phpunit --coverage-clover build/logs/clover.xml
env:
ENGINE: PDO_MYSQL
EMULATE_PREPARES: ${{ matrix.emulate-prepares }}

- name: Upload coverage report to Coveralls
run: vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.5.1](https://github.com/brick/geo/releases/tag/0.5.1) - 2021-04-20

🐛 **Fixes**

- Fixed bug with PDO MySQL when using non-emulated prepared statements

## [0.5.0](https://github.com/brick/geo/releases/tag/0.5.0) - 2021-03-05

🐛 **Fixes**
Expand Down
4 changes: 4 additions & 0 deletions phpunit-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
} else {
switch ($engine) {
case 'PDO_MYSQL':
$emulatePrepares = getenv('EMULATE_PREPARES') === 'ON';

echo 'Using PDOEngine for MySQL' . PHP_EOL;
echo 'with emulated prepares ' . ($emulatePrepares ? 'ON' : 'OFF') . PHP_EOL;

$pdo = new PDO('mysql:host=127.0.0.1;port=3306', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulatePrepares);

$pdo->exec('DROP DATABASE IF EXISTS geo_tests');
$pdo->exec('DROP DATABASE IF EXISTS geo_tests_tmp');
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/PDOEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function executeQuery(string $query, array $parameters) : array
protected function getGeomFromWKBSyntax(): string
{
if ($this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'mysql') {
return 'ST_GeomFromWKB(_binary ?, ?)';
return 'ST_GeomFromWKB(BINARY ?, ?)';
}

return parent::getGeomFromWKBSyntax();
Expand Down

0 comments on commit 5ebcd63

Please sign in to comment.