php连接oracle

首先修改php.ini,将下列行前的分号去掉。

extension=php_pdo_oci.dll

extension=php_pdo_oci8.dll

extension=php_oci8.dll

由于本人机子上有oracle客户端,oracle客户端是否必需无法验证。

<?php

$conn = oci_connect('demo', 'demo', '180.210.3.191/mess');
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$stid = oci_parse($conn, "select sid,message,sendtime from tb_liuyi");
oci_execute($stid);

while (($row = oci_fetch_array($stid, OCI_BOTH))) {
    echo $row[0].'+'.$row[1].'+'.$row[2].'<br>';
    //echo $row[SID].'+'.$row[MESSAGE].'+'.$row[SENDTIME].'<br>';//此行也同等效果,可以print_r
}

oci_free_statement($stid);

 $stmt=oci_parse($conn,"insert into tb_liuyi (SID, MESSAGE, SENDTIME)
values (126, 'xxxxx126', to_date('20101111002000','yyyymmddhh24miss'))");
 oci_execute($stmt, OCI_DEFAULT);
 $committed = oci_commit($conn);
 if (!$committed) {
    $error = oci_error($conn);
    echo 'Commit failed. Oracle reports: ' . $error['message'];
 }
oci_close($conn);

?>

收藏于 2012-01-30

posted on 2015-06-01 15:13  阮減显  阅读(93)  评论(0编辑  收藏  举报

导航