Gábor Varga
Gábor Varga

Reputation: 840

How to handle Oracle CLOB in PHP?

I asked a question like this yesterday, but I haven't got any answers yet.

The point: How can I get the CLOB reference such as in an insert into or update statement:

$sql = "INSERT INTO table (data) VALUES (EMPTY_CLOB()) RETURNING data INTO :data";
$statement = oci_parse($conn, $sql);
$descriptor = oci_new_descriptor($conn, OCI_DTYPE_LOB);
oci_bind_by_name($statement, ':data', $descriptor, -1, OCI_B_CLOB);
oci_execute($statement);
$descriptor->save('5000 chars');
oci_free_descriptor($descriptor);

So, I want call the clob save method without insert and update statement. So I tried:

$sql = "SELECT data FROM table WHERE id = " . $fooid;
$statement = oci_parse($conn, $sql);
oci_execute($statement);
$row = oci_fetch_assoc($statement);
$row['DATA']->save('5000 chars');

How to?

Thx.

Upvotes: 0

Views: 3804

Answers (1)

Gábor Varga
Gábor Varga

Reputation: 840

$sql = "INSERT INTO table t (t.data) VALUES (EMPTY_CLOB()) RETURNING t.data.clob INTO :data";
$statement = oci_parse($conn, $sql);
$descriptor = oci_new_descriptor($conn, OCI_DTYPE_LOB);
oci_bind_by_name($statement, ':data', $descriptor, -1, OCI_B_CLOB);
oci_execute($statement, 0); //no commit!!!
$descriptor->save('5000 chars');
oci_commit($conn);
oci_free_descriptor($descriptor);

Upvotes: 1

Related Questions