Skip to content

Commit

Permalink
Use $maxLength = 0 by default when calling PDOStatement::bindParam()
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Dec 28, 2021
1 parent b4f49c0 commit bf72469
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Driver/PDO/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ public function bindParam(
$type = $this->convertParamType($type);

try {
return $this->stmt->bindParam($param, $variable, $type, ...array_slice(func_get_args(), 3));
return $this->stmt->bindParam(
$param,
$variable,
$type,
$length ?? 0,
...array_slice(func_get_args(), 4)
);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Functional/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ public function testReuseStatementWithReboundParam(): void
self::assertEquals(2, $result->fetchOne());
}

public function testBindParamWithNullLength(): void
{
$this->connection->insert('stmt_test', ['id' => 1]);

$stmt = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?');

$value = 1;
$stmt->bindParam(1, $value, ParameterType::INTEGER, null);

self::assertEquals(1, $stmt->executeQuery()->fetchOne());
}

/**
* @param mixed $expected
*
Expand Down

0 comments on commit bf72469

Please sign in to comment.