Skip to content

Commit ae7912a

Browse files
committed
fix prepare statement oci8
1 parent 7307ff0 commit ae7912a

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

system/Database/OCI8/PreparedQuery.php

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

76-
foreach (array_keys($data) as $key) {
77-
oci_bind_by_name($this->statement, ':' . $key, $data[$key]);
76+
$blobs = [];
77+
78+
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);
82+
} else {
83+
oci_bind_by_name($this->statement, ':' . $key, $item);
84+
}
7885
}
7986

80-
$result = oci_execute($this->statement, $this->db->commitMode);
87+
$result = oci_execute($this->statement, $blobs === [] ? $this->db->commitMode : OCI_NO_AUTO_COMMIT);
88+
89+
if ($blobs !== []) {
90+
foreach ($blobs as $key => $blob) {
91+
if (! $blob->save($data[$key])) {
92+
oci_rollback($this->db->connID);
93+
return false;
94+
}
95+
}
96+
97+
oci_commit($this->db->connID);
98+
99+
foreach ($blobs as $blob) {
100+
$blob->free();
101+
}
102+
}
81103

82104
if ($result && $this->lastInsertTableName !== '') {
83105
$this->db->lastInsertedTableName = $this->lastInsertTableName;

0 commit comments

Comments
 (0)