yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

PHP 7 fix for bindValue #23

Closed snelg closed 8 years ago

snelg commented 8 years ago

bindValue breaks in PHP 7, but the fix is simple. Here's a minimal code sample that works in PHP 5, but not 7:

$conn = new Oci8('**redacted**', '**also redacted**', '**not for you to know**');
$statement = $conn->prepare("SELECT * FROM USERS WHERE ID = :id");
$userId = 1;
$statement->bindValue(':id', $userId);
$success = $statement->execute();
$results = $statement->fetchAll();
print_r($results);

In 7, it blows up with a "ORA-01722: invalid number", because by the time the oci_execute function is called, the bound $variable has disappeared. It seems that PHP 7 is smarter about disposing of variables it deems no longer necessary. So the copy of $variable that's created when bindValue is called disappears once bindValue exits.

My proposed fix in this patch is to simply add the $variable to $this->bindings by reference. That way, PHP will know that the variable itself needs to persist after bindValue exits.

yajra commented 8 years ago

Released on v1.0.1. Thanks a lot!

snelg commented 8 years ago

Unimportant anecdote: I've been using your package for over a year, and in the back of my mind I kind of wondered where the name "yajra" came from. When I was submitting this pull request, I finally figured it out. And then I felt extra dumb for not figuring it out earlier because, well, look at my username :)

-Glen S.