php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch PdoOciClobReadError-test-with-more-debug-output for PDO OCI Bug #60994

Patch version 2012-02-06 16:19 UTC

Return to Bug #60994 | Download this patch
Patch Revisions:

Developer: php.net@boedah.de

// coding: utf-8 

mb_internal_encoding('utf-8');

$dsn = 'oci:dbname=(DESCRIPTION=(ADDRESS_LIST=(
                ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
                (CONNECT_DATA=(SID=xe)));charset=AL32UTF8';
$username = 'USER';
$password = 'PW';

$lobTestTablename = 'TEST_LOB';
/*
create table TEST_LOB (
    tl_id         NUMBER(3),
    tl_byte_16    VARCHAR2(16 BYTE),
    tl_char_16    VARCHAR2(16 CHAR),
    tl_byte_4000  VARCHAR2(4000 BYTE),
    tl_char_4000  VARCHAR2(4000 CHAR),
    tl_blob       BLOB,
    tl_clob       CLOB,
    tl_date       DATE,
    tl_number     NUMBER
)
*/
$id = -1;

$data = '…';
$length = 8193;

// this actually works:
//$data = '.';
//$length = 100000;

$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("delete from $lobTestTablename where tl_id < 0");

$clobData = str_repeat($data, $length);
printf("writing into DB: strlen: %d, mb_strlen: %d\n", strlen($clobData), mb_strlen($clobData));

$pdoStmt = $pdo->prepare("insert into $lobTestTablename (tl_id, tl_clob) values (?, ?)");
/* @var $pdoStmt PDOStatement */

$pdoStmt->bindParam(1, $id, PDO::PARAM_INT, null, null);
$pdoStmt->bindParam(2, $clobData, PDO::PARAM_STR, strlen($clobData), null);
$pdoStmt->execute();

$pdoStmt = $pdo->query("select length(tl_clob) from $lobTestTablename where TL_ID = $id");
printf("length in DB: %d\n", $pdoStmt->fetchColumn());

$pdoStmt = $pdo->query("select * from $lobTestTablename where TL_ID = $id");
/* @var $pdoStmt PDOStatement */
$row = $pdoStmt->fetch(PDO::FETCH_ASSOC);

var_dump($row['TL_CLOB']);

$dataRead = stream_get_contents($row['TL_CLOB']);

printf("stream eof? %s\n", var_export(feof($row['TL_CLOB']), true));
printf("read back in: strlen: %d, mb_strlen: %d\n", strlen($dataRead), mb_strlen($dataRead));
printf("values equal: %s\n", var_export($clobData === $dataRead, true));
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 00:01:27 2024 UTC