{"id":271,"date":"2016-02-13T11:00:40","date_gmt":"2016-02-13T10:00:40","guid":{"rendered":"http:\/\/www.speich.net\/articles\/?p=271"},"modified":"2019-10-06T09:54:28","modified_gmt":"2019-10-06T07:54:28","slug":"streaming-large-data-lobs-directly-into-an-oracle-database-with-php","status":"publish","type":"post","link":"https:\/\/www.speich.net\/articles\/en\/2016\/02\/13\/streaming-large-data-lobs-directly-into-an-oracle-database-with-php\/","title":{"rendered":"Streaming large data (LOBs) directly into an Oracle database with PHP"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The OCI library allows you to stream large data in chunks directly into a LOB instead of loading it completely into memory first. This technique is only mentioned in the article <a title=\"Working with LOBs in Oracle and PHP\" href=\"http:\/\/www.oracle.com\/technetwork\/articles\/fuecks-lobs-095315.html\" target=\"_blank\" rel=\"noopener noreferrer\">Working with LOBs in Oracle and PHP<\/a> on the Oracle Technology Network, but no code example is given there, so here&#8217;s my take:<\/p>\n\n\n\n<pre><code class=\"language-php\">$sql = \"INSERT INTO myTable (myUploadBinary)\n  VALUES (EMPTY_BLOB())\n  RETURNING myUploadBinary INTO :myBinary\";\n$stmt = oci_parse($conn, $sql);\n$lob = oci_new_descriptor($conn, OCI_D_LOB);\noci_bind_by_name($stmt, \":myBinary\", $lob, -1, OCI_B_BLOB);\n$this-&gt;execute($stmt);\n\n$handle = fopen(\"myFile\", 'r');\nwhile (($buffer = fread($handle, 2048)) != '') {\n  $lob-&gt;write($buffer);\n  $lob-&gt;flush();\n  flush();\n  ob_flush();\n}\nfclose($handle);\noci_commit();\noci_free_statement($stmt);\n$lob-&gt;free();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The OCI library allows you to stream large data in chunks directly into a LOB instead of loading it completely into memory first. This technique is only mentioned in the article Working with LOBs in Oracle and PHP on the Oracle Technology Network, but no code example is given there, so here&#8217;s my take: $sql &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.speich.net\/articles\/en\/2016\/02\/13\/streaming-large-data-lobs-directly-into-an-oracle-database-with-php\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Streaming large data (LOBs) directly into an Oracle database with PHP&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[224,69,81],"class_list":["post-271","post","type-post","status-publish","format-standard","hentry","category-php","tag-lob","tag-oracle","tag-sql","entry"],"_links":{"self":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/comments?post=271"}],"version-history":[{"count":4,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/271\/revisions"}],"predecessor-version":[{"id":1655,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/271\/revisions\/1655"}],"wp:attachment":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/media?parent=271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/categories?post=271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/tags?post=271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}