downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

oci_result> <oci_password_change
Last updated: Fri, 13 Nov 2009

view this page in

oci_pconnect

(PHP 5, PECL OCI8 >= 1.1.0)

oci_pconnect持続的接続を使用してOracle データベースに接続する

説明

resource oci_pconnect ( string $username , string $password [, string $db [, string $charset [, int $session_mode ]]] )

Oracle サーバへの持続的接続を生成し、ログオンします。

持続的接続はキャッシュされ、リクエスト間で再利用されることで、 各ページロードのオーバーヘッドを軽減します。 典型的な PHP アプリケーションでは、Apache の子プロセス (もしくは PHP FastCGI/CGI プロセス) ごとに Oracle サーバに対してオープンされた単一の持続的接続を有します。 より詳細な情報については、持続的データベース接続 のセクションを参照してください。

パラメータ

username

Oracle のユーザ名。

password

username のパスワード。

db

このオプションのパラメータには、ローカル Oracle インスタンスの名前か tnsnames.ora における接続先のエントリ名を指定することができます。

指定しない場合は、PHP は環境変数 ORACLE_SID および TWO_TASK を用いてローカルの Oracle インスタンス名および tnsnames.ora の場所を見つけます。

charset

Oracle サーバのバージョン 9.2 以降を使用している場合、新規接続を確立する際に charset パラメータを指定することができます。 Oracleサーバ < 9.2 を使用している場合、このパラメータは無視され、 かわりに環境変数 NLS_LANG が使用されます。

session_mode

パラメータ session_mode はバージョン 1.1 からり用可能で、次の値を受け付けます: OCI_DEFAULT, OCI_SYSOPER, OCI_SYSDBAOCI_SYSOPER もしくは OCI_SYSDBA のいずれかが指定された場合、 oci_connect() は外部の信用を利用して 権限付きの接続を確立しようとします。 デフォルトでは権限付きの接続は無効です。有効にするためには、oci8.privileged_connect をオンにしてください。

返り値

接続 ID、あるいはエラー時に FALSE を返します。

注意

注意: oci8 拡張モジュールのバージョン 1.1 から、持続的 Oracle 接続の生存時間と最大数が次の設定値を設定することで調整可能になりました: oci8.persistent_timeout, oci8.ping_interval, oci8.max_persistent

注意: もし PHP を Oracle Instant Client と併用している場合、 次に解説されている簡単な接続ネーミングメソッドを使用することができます: » http://download.oracle.com/docs/cd/E11882_01/network.112/e10836/naming.htm#NETAG255 。 基本的にデータベース名として "//db_host[:port]/database_name" を指定できることを意味します。しかし、 古いネーミングメソッドを使用したい場合、ORACLE_HOME もしくは TNS_ADMIN のいずれかを設定 しなければなりません

注意: PHP バージョン 5.0.0 以前では、代わりに ociplogon() を使用しなければなりません。 まだこの名前を使用することができ、下位互換性のため oci_pconnect() への別名として残されていますが、 推奨されません。

参考



oci_result> <oci_password_change
Last updated: Fri, 13 Nov 2009
 
add a note add a note User Contributed Notes
oci_pconnect
php at jaggard dot org dot uk
09-Oct-2008 04:38
[Editor's note: OCI8 1.3 should not experience the problem described in this user comment. The first use of such a connection will return an Oracle error which will trigger a cleanup in PHP.  Subsequent persistent connection calls will then succeed.  For high availability you might consider doing consecutive oci_pconnect calls in your script.]

If you connect using oci_pconnect and the connection has logged you off but is still valid, there seems to be no way to re-use that connection. The next time I try oci_pconnect and then perform an oci_execute operation, I get a "ORA-01012: not logged on" warning. This problem remains, even if I close the connection using oci_close. I ended up with the following (rather annoying) code.

<?php
   
function getOracleConnection()
    {
      if (!
function_exists('oci_pconnect'))
        return
false;
     
$toReturn = oci_pconnect('user', 'pass', 'db');
      if (
$testRes = @oci_parse($toReturn, 'SELECT Count(group_type_code) FROM pvo.group_type'))
        if (@
oci_execute($testRes))
          if (@
oci_fetch_array($testRes))
            return
$toReturn;
     
oci_close($toReturn);
      if (!
function_exists('oci_connect'))
        return
false;
     
$toReturn = oci_connect('user', 'pass', 'db');
      if (
$testRes = @oci_parse($toReturn, 'SELECT Count(group_type_code) FROM pvo.group_type'))
        if (@
oci_execute($testRes))
          if (@
oci_fetch_array($testRes))
            return
$toReturn;
     
oci_close($toReturn);
      if (!
function_exists('oci_new_connect'))
        return
false;
     
$toReturn = oci_new_connect('user', 'pass', 'db');
      if (
$testRes = @oci_parse($toReturn, 'SELECT Count(group_type_code) FROM pvo.group_type'))
        if (@
oci_execute($testRes))
          if (@
oci_fetch_array($testRes))
            return
$toReturn;
     
oci_close($toReturn);
      return
false;
    }
?>
alvaro at demogracia dot com
11-Sep-2008 03:54
If oci_pconnect() fails it raises a PHP warning.
M0no at ethonfusino dot com
21-Nov-2002 06:04
If your oracle database is on a remote system within your local network and you don't want to worry about the tnsnames file you can try this.

$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.XX.XXX)(PORT = 1521)))(CONNECT_DATA=(SID=XXXX)))";

$c1 = ocilogon("name","password",$db);

Hope this helps someone.
kakukkfu at mailbox dot hu
26-Sep-2002 06:09
Better to insert needed variables into apache(!) (or your webserver - respectively) start script.

For example on UNIX systems /etc/init.d/apache would contain following lines before anything else:

#!/bin/bash

if [ -f ~oracle/.profile ]; then
        source ~oracle/.profile
fi

The ~oracle/.profile has the appropiate settings to start an Oracle database so it is always up-to-date for PHP, too. (If settings are changed, don't forget to restart your webserver.) This way you just no need to worry what to include or define for PHP.

oci_result> <oci_password_change
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites