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, 20 Nov 2009

view this page in

oci_pconnect

(PHP 5, PECL OCI8 >= 1.1.0)

oci_pconnectConnect to an Oracle database using a persistent connection

Descrierea

resource oci_pconnect ( string $username , string $password [, string $connection_string [, string $character_set [, int $session_mode ]]] )

Creates a persistent connection to an Oracle server and logs on.

Persistent connections are cached and re-used between requests, resulting in reduced overhead on each page load; a typical PHP application will have a single persistent connection open against an Oracle server per Apache child process (or PHP FastCGI/CGI process). See the Persistent Database Connections section for more information.

Parametri

username

The Oracle user name.

password

The password for username .

connection_string

Contains the Oracle instance to connect to. It can be an » Easy Connect string, or a Connect Name from the tnsnames.ora file, or the name of a local Oracle instance

If not specified, PHP uses environment variables such as TWO_TASK (on Linux) or LOCAL (on Windows) and ORACLE_SID to determine the Oracle instance to connect to.

To use the Easy Connect naming method, PHP must be linked with Oracle 10g or greater Client libraries.

character_set

Utilizând Oracle server de versiune 9.2 sau ulterioară, puteţi să indicaţi charset în calitate de parametru, care va fi utilizat în noua conexiune. Dacă utilizaţi Oracle server < 9.2, acest parametru va fi ignorat şi în loc va fi utilizată variabila de mediu NLS_LANG.

session_mode

This parameter is available since version PECL oci8 1.1 and accepts the following values: OCI_DEFAULT, OCI_SYSOPER and OCI_SYSDBA. If either OCI_SYSOPER or OCI_SYSDBA were specified, this function will try to establish privileged connection using external credentials. Privileged connections are disabled by default. To enable them you need to set oci8.privileged_connect to On.

PHP 5.3 and PECL oci8 1.3.4 introduced the OCI_CRED_EXT mode value. This tells Oracle to use External or OS authentication, which must be configured in the database. The OCI_CRED_EXT flag can only be used with username of "/" and a empty password. oci8.privileged_connect may be On or Off.

OCI_CRED_EXT may be combined with the OCI_SYSOPER or OCI_SYSDBA modes.

OCI_CRED_EXT is not supported on Windows for security reasons.

Valorile întroarse

Returns a connection identifier or FALSE on error.

Note

Notă: Starting with PHP 5.1.2 and PECL oci8 1.1, the lifetime and maximum number of persistent Oracle connections can be tuned by setting the following configuration values: oci8.persistent_timeout, oci8.ping_interval and oci8.max_persistent.

Notă: In PHP versions before 5.0.0 you must use ociplogon() instead. The old function name can still be used in current versions, however it is deprecated and not recommended.

Vedeţi de asemenea



oci_result> <oci_password_change
Last updated: Fri, 20 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, 20 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites