码迷,mamicode.com
首页 > 数据库 > 详细

php 操作 oracle lob 数据2

时间:2015-06-17 09:23:56      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

CREATE SEQUENCE mylobs_id_seq
    NOMINVALUE
    NOMAXVALUE
    NOCYCLE
    CACHE 20
    NOORDER
INCREMENT BY 1;

CREATE TABLE mylobs (
    id NUMBER PRIMARY KEY,
    mylob CLOB
)

插入

<?php
header("content-type:text/html;charset=utf-8");
error_reporting(E_ALL);
set_time_limit(0);

echo "<pre>";

$conn=oci_connect(‘demo‘,‘demo‘,‘localhost/xe‘,‘utf8‘);

$sql = "INSERT INTO
        mylobs
          (
            id,
            mylob
          )
       VALUES
          (
            mylobs_id_seq.NEXTVAL,
            EMPTY_CLOB()
          )
       RETURNING
          mylob INTO :mylob_loc";

$stmt = oci_parse($conn, $sql);

$myLOB = oci_new_descriptor($conn, OCI_D_LOB);

oci_bind_by_name($stmt, ":mylob_loc", $myLOB, -1, OCI_B_CLOB);

oci_execute($stmt, OCI_DEFAULT) or die ("Unable to execute query\n");

$content=str_repeat(‘你‘,80000);
if ( !$myLOB->save($content) ) {
    oci_rollback($conn);
} else {
    oci_commit($conn);
}
oci_free_statement($stmt);
$myLOB->free();
oci_close($conn);

 

查询

<?php
header("content-type:text/html;charset=utf-8");
error_reporting(E_ALL);
set_time_limit(0);

echo "<pre>";

$conn=oci_connect(‘demo‘,‘demo‘,‘localhost/xe‘,‘utf8‘);


$sql = "SELECT * FROM mylobs ORDER BY id";

$stmt = oci_parse($conn, $sql);

oci_execute($stmt) or die ("Unable to execute query\n");

while ( $row = oci_fetch_assoc($stmt) ) {
    echo "ID: {$row[‘ID‘]}, ";
    echo $row[‘MYLOB‘]->load()."\n";
}
oci_free_statement($stmt);

oci_close($conn);


 

修改

 

<?php
header("content-type:text/html;charset=utf-8");
error_reporting(E_ALL);
set_time_limit(0);

echo "<pre>";

$conn=oci_connect(‘demo‘,‘demo‘,‘localhost/xe‘,‘utf8‘);


$sql = "SELECT mylob FROM mylobs WHERE id = 1 FOR UPDATE";

$stmt = oci_parse($conn, $sql);

oci_execute($stmt, OCI_DEFAULT) or die ("Unable to execute query\n");

if ( FALSE === ($row = oci_fetch_assoc($stmt) ) ) {
    oci_rollback($conn);
    die ("Unable to fetch row\n");
}

if ( !$row[‘MYLOB‘]->truncate() ) {
    oci_rollback($conn);
    die ("Failed to truncate LOB\n");
}

if ( !$row[‘MYLOB‘]->save(‘UPDATE: ‘.date(‘H:i:s‘,time()) ) ) {
    oci_rollback($conn);
} else {
    oci_commit($conn);
}

oci_free_statement($stmt);
$row[‘MYLOB‘]->free();


oci_close($conn);

php 操作 oracle lob 数据2

标签:

原文地址:http://www.cnblogs.com/songzhenghe/p/4582318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!