成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? PHP:oci_close()的用法_Oracle函數
全站頭部文字 我要出現在這里
PHP:oci_close()的用法_Oracle函數 739 2023-12-12   

oci_close

(PHP 5, PECL OCI8 >= 1.1.0)

oci_close — 關閉 Oracle 連接

說明

bool oci_close ( resource $connection )

oci_close() 將 Oracle 連接 connection 關閉。

Note:

自版本 1.1 起 oci_close() 正確關閉 Oracle 連接。使用 oci8.old_oci_close_semantics 選項來恢復本函數的舊行為。

成功時返回 TRUE, 或者在失敗時返回 FALSE。

Note:

在 PHP 5.0.0 之前的版本必須使用 ocilogoff() 替代本函數。該函數名仍然可用,為向下兼容作為 oci_close() 的別名。不過其已被廢棄,不推薦使用。

參數

connection

An Oracle connection identifier returned by oci_connect(), oci_pconnect(), or oci_new_connect().

返回值

成功時返回 TRUE, 或者在失敗時返回 FALSE。

范例

Example #1 Closing a connection

Resources associated with a connection should be closed to ensure the underlying database connection is properly terminated and the database resources are released.

<?php

$conn = oci_connect('hr', 'welcome', 'localhost/XE');
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$stid = oci_parse($conn, 'SELECT * FROM departments');
$r = oci_execute($stid);
oci_fetch_all($stid, $res);
var_dump($res);

// Free the statement identifier when closing the connection
oci_free_statement($stid);
oci_close($conn);

?>

Example #2 Database connections are not closed until all references are closed

The internal refcount of a connection identifier must be zero before the underlying connection to the database is closed.

<?php

$conn = oci_connect('hr', 'welcome', 'localhost/XE');
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$stid = oci_parse($conn, 'SELECT * FROM departments');  // this increases the refcount on $conn
oci_execute($stid);
oci_fetch_all($stid, $res);
var_dump($res);

oci_close($conn);

// $conn is no long usable in the script but the underlying database
// connection is still held open until $stid is freed.
var_dump($conn);  // prints NULL  

// While PHP sleeps, querying the Oracle V$SESSION view in a
// terminal window will show that the database user is still connected.
sleep(10);

// When $stid is freed, the database connection is physically closed
oci_free_statement($stid);  

// While PHP sleeps, querying the Oracle V$SESSION view in a
// terminal window will show that the database user has disconnected.
sleep(10);

?>

Example #3 Closing a connection opened more than once

When database credentials are reused, both connections must be closed before the underlying database connection is closed.

<?php

$conn1 = oci_connect('hr', 'welcome', 'localhost/XE');

// Using the same credentials reuses the same underlying database connection
// Any uncommitted changes done on $conn1 will be visible in $conn2
$conn2 = oci_connect('hr', 'welcome', 'localhost/XE');

// While PHP sleeps, querying the Oracle V$SESSION view in a
// terminal window will show that only one database user is connected.
sleep(10);

oci_close($conn1); // doesn't close the underlying database connection
var_dump($conn1);  // prints NULL because the variable $conn1 is no longer usable
var_dump($conn2);  // displays that $conn2 is still a valid connection resource

?>

Example #4 Connections are closed when variables go out of scope

When all variables referencing a connection go out of scope and are freed by PHP, a rollback occurs (if necessary) and the underlying connection to the database is closed.

<?php

function myfunc() {
    $conn = oci_connect('hr', 'hrpwd', 'localhost/XE');
    if (!$conn) {
        $e = oci_error();
        trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }

    $stid = oci_parse($conn, 'UPDATE mytab SET id = 100');
    oci_execute($stid, OCI_NO_AUTO_COMMIT);
    return "Finished";
}

$r = myfunc();
// At this point a rollback occurred and the underlying database connection was released.

print $r;  // displays the function return value "Finished"

?>

注釋

Note:

Variables that have a dependency on the connection identifier, such as statement identifiers returned by oci_parse(), must also be freed before the underlying database connection is closed.

Note:

Prior to version PHP 5.1.2 (PECL OCI8 1.1) oci_close() was a no-op. In more recent versions it correctly closes the Oracle connection. Use oci8.old_oci_close_semantics option to restore old behavior of this function.

Note:

The oci_close() function does not close the underlying database connections created with oci_pconnect().

Note:

In PHP versions before 5.0.0 you must use ocilogoff() instead. 在當前版本中,舊的函數名還可以被使用,但已經被廢棄并不建議使用。

參見

oci_connect() - 建立一個到 Oracle 服務器的連接 oci_free_statement() - 釋放關聯于語句或游標的所有資源


主站蜘蛛池模板: 康熙王朝50集免费观看投屏电视剧| 电影英雄| cqtv| 包头电视台| 菊次郎的夏天钢琴谱简谱| 生死搏斗| 鲍鱼视频在线观看| 一碗泡面的热量是多少大卡| 关鹏| 都市频道在线直播| 红日歌词完整版| 林忆莲唱哭李宗盛现场| 小学一年级古诗《风》| 老江湖 电影| 太原教育电视台| 六年级上册英语书电子版翻译| 夜魔电影| 就爱小姐姐| 大浴女电视剧所有演员表| 读书笔记经典常谈| 黄网站在线免费| 郭亚菲| 浙江卫视是几台| 邓伦是哪里人| 2024年血糖标准| 玫瑰的故事剧照| 高一英语必修一| 徐少强全部电影| 欲望号列车| 北京卫视今晚的电视剧是什么| 韩国电影闵度允主演电影| 王妍个人资料简介| 卢昱晓电视剧| abo血型鉴定实验报告| 女干.com| 红海行动2免费看完整版| 密杀名单| 电影名叫《保姆》| 王同辉| 琉璃演员表全部演员介绍| 源代码 电影|

?。。≌鹃L長期在線接!??!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103