How do you save large chunks of text with oracle?

Save large chunks of text with clob

if(!$this->validate()){
    return false;
}
$model = new Article();
$model->TITLE = $this->TITLE;
$model->CID = $this->CID;
$model->CONTENT_DATA = $this->CONTENT_DATA;  //CONTENT_DATACLOB
$model->save();

the following error occurs

SQLSTATE[HY000]: General error: 1461 OCIStmtExecute: ORA-01461: can bind a LONG value only for insert into a LONG column (/tmp/pdo_oci/oci_statement.c:159)

then I rewrote the ocicommand class in yii2, the modified bindValues and bindPendingParams methods

protected function bindPendingParams()
    {
        foreach ($this->_pendParams as $name => $value) {
            if(isset($value[2])){
                $this->pdoStatement->bindParam($name, $value[0], $value[1], $value[2]);
            }else{
                $this->pdoStatement->bindParam($name, $value[0], $value[1]);
            }
        }
        $this->_pendParams = [];
    }

in this way, no matter how long the data is, it can be written to the database.
but with each update, the content becomes less.
write


for the first time

there will be fewer updates.
is really incomprehensible.

Mar.28,2021

found the problem

$this->pdoStatement->bindParam($name, $value[0], $value[1], $value[2]);

when writing data to a field of type clob in the database using the above method, the length of the data to be bound is the value of $value [2], which is calculated by
strlen
which is a pit.
example:
writes data to the database "Hello, World, Hello world." And so on. "A large amount of text data with a length of 50000
written for the first time without any problem.
read it from the database with php

."
$content = stream_get_content($row['content']);
echo strlen($content);
//50000

so every time you update, you lose data.

the solution is that after the data is submitted to the background, first base64 the large text
, then calculate the length, and then write it to the database.
as for the efficiency of base64 large text, I did not test

Menu