Skip to content

Commit 1121259

Browse files
committed
fix prepare statement oci8
1 parent 5977434 commit 1121259

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

system/Database/OCI8/PreparedQuery.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,34 @@ public function _execute(array $data): bool
7373
throw new BadMethodCallException('You must call prepare before trying to execute a prepared statement.');
7474
}
7575

76-
$blobs = [];
76+
$binaryData = [];
7777

7878
foreach ($data as $key => $item) {
79-
if (is_string($item) && mb_detect_encoding($item, 'UTF-8', true) === false) {
80-
$blobs[$key] = oci_new_descriptor($this->db->connID, OCI_D_LOB);
81-
oci_bind_by_name($this->statement, ':' . $key, $blobs[$key], -1, OCI_B_BLOB);
79+
if (is_string($item) && $this->isBinary($item)) {
80+
$binaryData[$key] = oci_new_descriptor($this->db->connID, OCI_D_LOB);
81+
oci_bind_by_name($this->statement, ':' . $key, $binaryData[$key], -1, OCI_B_BLOB);
8282
} else {
8383
oci_bind_by_name($this->statement, ':' . $key, $item);
8484
}
8585
}
8686

87-
$result = oci_execute($this->statement, $blobs === [] ? $this->db->commitMode : OCI_NO_AUTO_COMMIT);
87+
$result = oci_execute(
88+
$this->statement,
89+
$binaryData === [] ? $this->db->commitMode : OCI_NO_AUTO_COMMIT
90+
);
8891

89-
if ($blobs !== []) {
90-
foreach ($blobs as $key => $blob) {
92+
if ($binaryData !== []) {
93+
foreach ($binaryData as $key => $blob) {
9194
if (! $blob->save($data[$key])) {
9295
oci_rollback($this->db->connID);
96+
9397
return false;
9498
}
9599
}
96100

97101
oci_commit($this->db->connID);
98102

99-
foreach ($blobs as $blob) {
103+
foreach ($binaryData as $blob) {
100104
$blob->free();
101105
}
102106
}

0 commit comments

Comments
 (0)