Skip to content

Commit

Permalink
Fix PDOStatement::bindParam() expects parameter 1 to be string (#116)
Browse files Browse the repository at this point in the history
* Fix PDOStatement::bindParam() expects parameter 1 to be string, int given

* Add test
  • Loading branch information
sy-records authored Aug 13, 2021
1 parent aa1a437 commit 1b421d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/Database/PDOStatementProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function setFetchMode(int $mode, ...$args): bool
return $this->__object->setFetchMode(...$this->setFetchModeContext);
}

public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null): bool
public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = 0, $driver_options = null): bool
{
$this->bindParamContext[$parameter] = [$variable, $data_type, $length, $driver_options];
return $this->__object->bindParam($parameter, $variable, $data_type, $length, $driver_options);
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/Database/PDOStatementProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,18 @@ public function testSetFetchMode(array $expected, array $args, string $message)
self::assertEquals($expected, $stmt->fetchAll(), $message);
});
}

/**
* @covers \Swoole\Database\PDOStatementProxy::bindParam()
*/
public function testBindParam()
{
Coroutine\run(function () {
$stmt = $this->getPdoPool()->get()->prepare('SHOW TABLES like ?');
$table = 'NON_EXISTING_TABLE_NAME';
$stmt->bindParam(1, $table, PDO::PARAM_STR);
$stmt->execute();
self::assertIsArray($stmt->fetchAll());
});
}
}

0 comments on commit 1b421d5

Please sign in to comment.