diff --git a/src/Query.php b/src/Query.php index b72775c..5e58032 100644 --- a/src/Query.php +++ b/src/Query.php @@ -99,7 +99,9 @@ protected static function replaceHolder($pdo, $key, $type, $value, &$bind_values throw new \DomainException(sprintf('param "%s" is integer out of range.', $key)); } - if (!preg_match('/\A-?[1-9][0-9]*\z/', $s)) { + $is_zero = $s === 0 || $s === '0'; + + if (!$is_zero && !preg_match('/\A-?[1-9][0-9]*\z/', $s)) { throw new \DomainException(); } diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 11de6f7..277948a 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -11,12 +11,14 @@ final class QueryTest extends \PHPUnit\Framework\TestCase public function test() { $pdo = new DummyPDO; - $orig = "string: :a@string\nint :b@int\nstring: :a@string\nint :b@int"; + $orig = "string: :a@string\nint :b@int\nstring: :a@string\nint :b@int\nint :c1@int\nint :c1@int"; $stmt = Query::build($pdo, $orig, [ ':a' => 'AAAA', ':b' => '2222', + ':c1' => '0', + ':c2' => 0, ]); - $expected = 'string: @AAAA@ int 2222 string: @AAAA@ int 2222'; + $expected = 'string: @AAAA@ int 2222 string: @AAAA@ int 2222 int 0 int 0'; $this->assertSame($expected, $stmt->queryString); } }