Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 8509

php-manual-pt_BR-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>oci_new_connect</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Manual do PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Funções do Oracle 8"
HREF="ref.oci8.html"><LINK
REL="PREVIOUS"
TITLE="oci_new_collection"
HREF="function.oci-new-collection.html"><LINK
REL="NEXT"
TITLE="oci_new_cursor"
HREF="function.oci-new-cursor.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual do PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.oci-new-collection.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.oci-new-cursor.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.oci-new-connect"
></A
>oci_new_connect</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN153703"
></A
><P
>    (PHP 5)</P
>oci_new_connect&nbsp;--&nbsp;Establishes a new connection to the Oracle server</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN153706"
></A
><H2
>Descrição</H2
>resource <B
CLASS="methodname"
>oci_new_connect</B
> ( string username, string password [, string db [, string charset [, int session_mode]]] )<BR
></BR
><P
>&#13;   Establishes a new connection to an Oracle server and logs on.
  </P
><P
>&#13;   Unlike <A
HREF="function.oci-connect.html"
><B
CLASS="function"
>oci_connect()</B
></A
> and 
   <A
HREF="function.oci-pconnect.html"
><B
CLASS="function"
>oci_pconnect()</B
></A
>, <B
CLASS="function"
>oci_new_connect()</B
>
   does not cache connections and will always return a brand-new freshly
   opened connection handle. This is useful if your application needs
   transactional isolation between two sets of queries.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN153731"
></A
><H2
>Parâmetros</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>username</CODE
></DT
><DD
><P
>&#13;       The Oracle user name.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>password</CODE
></DT
><DD
><P
>&#13;       The password for <CODE
CLASS="parameter"
>username</CODE
>.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>db</CODE
></DT
><DD
><P
>&#13;       This optional parameter can either contain the name of the local
       Oracle instance or the name of the entry in
       <TT
CLASS="filename"
>tnsnames.ora</TT
>.
      </P
><P
>&#13;       If the not specified, PHP uses environment variables
       <TT
CLASS="literal"
>ORACLE_SID</TT
> and <TT
CLASS="literal"
>TWO_TASK</TT
> to
       determine the name of local Oracle instance and location of 
       <TT
CLASS="filename"
>tnsnames.ora</TT
> accordingly.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>charset</CODE
></DT
><DD
><P
>Com o Oracle server 9.2 e seguintes, você pode
 indicar o parâmetro <CODE
CLASS="parameter"
>charset</CODE
>, que será utilizado na nova
 conexão. Se você estiver utilizando Oracle server &#60; 9.2, este parâmetro será ignorado
 e a variável de ambiente NLS_LANG deverá ser utilizada.</P
></DD
><DT
><CODE
CLASS="parameter"
>session_mode</CODE
></DT
><DD
><P
>&#13;       This parameter is available since version 1.1 and accepts the
       following values: <TT
CLASS="constant"
><B
>OCI_DEFAULT</B
></TT
>,
       <TT
CLASS="constant"
><B
>OCI_SYSOPER</B
></TT
> and <TT
CLASS="constant"
><B
>OCI_SYSDBA</B
></TT
>.
       If either <TT
CLASS="constant"
><B
>OCI_SYSOPER</B
></TT
> or
       <TT
CLASS="constant"
><B
>OCI_SYSDBA</B
></TT
> 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 <A
HREF="missing-stuff.html#ini.oci8.privileged_connect"
>oci8.privileged_connect</A
>
       to <TT
CLASS="literal"
>On</TT
>.
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN153774"
></A
><H2
>Valores de retornado</H2
><P
>&#13;   Returns a connection identifier or <TT
CLASS="constant"
><B
>FALSE</B
></TT
> on error.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN153778"
></A
><H2
>Exemplos</H2
><P
>&#13;   The following demonstrates how you can separate connections.
   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN153781"
></A
><P
><B
>Exemplo 1. <B
CLASS="function"
>oci_new_connect()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">echo </font><font color="#DD0000">"&lt;html&gt;&lt;pre&gt;"</font><font color="#007700">;<br /></font><font color="#0000BB">$db </font><font color="#007700">= </font><font color="#DD0000">""</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$c1 </font><font color="#007700">= </font><font color="#0000BB">oci_connect</font><font color="#007700">(</font><font color="#DD0000">"scott"</font><font color="#007700">, </font><font color="#DD0000">"tiger"</font><font color="#007700">, </font><font color="#0000BB">$db</font><font color="#007700">);<br /></font><font color="#0000BB">$c2 </font><font color="#007700">= </font><font color="#0000BB">oci_new_connect</font><font color="#007700">(</font><font color="#DD0000">"scott"</font><font color="#007700">, </font><font color="#DD0000">"tiger"</font><font color="#007700">, </font><font color="#0000BB">$db</font><font color="#007700">);<br /><br />function </font><font color="#0000BB">create_table</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"create table scott.hallo (test<br />varchar2(64))"</font><font color="#007700">);<br />&nbsp;&nbsp;</font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br />&nbsp;&nbsp;echo </font><font color="#0000BB">$conn </font><font color="#007700">. </font><font color="#DD0000">" created table\n\n"</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">drop_table</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"drop table scott.hallo"</font><font color="#007700">);<br />&nbsp;&nbsp;</font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br />&nbsp;&nbsp;echo </font><font color="#0000BB">$conn </font><font color="#007700">. </font><font color="#DD0000">" dropped table\n\n"</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">insert_data</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"insert into scott.hallo<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;values('$conn' || ' ' || to_char(sysdate,'DD-MON-YY HH24:MI:SS'))"</font><font color="#007700">);<br />&nbsp;&nbsp;</font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">OCI_DEFAULT</font><font color="#007700">);<br />&nbsp;&nbsp;echo </font><font color="#0000BB">$conn </font><font color="#007700">. </font><font color="#DD0000">" inserted hallo\n\n"</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">delete_data</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"delete from scott.hallo"</font><font color="#007700">);<br />&nbsp;&nbsp;</font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">OCI_DEFAULT</font><font color="#007700">);<br />&nbsp;&nbsp;echo </font><font color="#0000BB">$conn </font><font color="#007700">. </font><font color="#DD0000">" deleted hallo\n\n"</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">commit</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;</font><font color="#0000BB">oci_commit</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">);<br />&nbsp;&nbsp;echo </font><font color="#0000BB">$conn </font><font color="#007700">. </font><font color="#DD0000">" committed\n\n"</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">rollback</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;</font><font color="#0000BB">oci_rollback</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">);<br />&nbsp;&nbsp;echo </font><font color="#0000BB">$conn </font><font color="#007700">. </font><font color="#DD0000">" rollback\n\n"</font><font color="#007700">;<br />}<br /><br />function </font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"select * from scott.hallo"</font><font color="#007700">);<br />&nbsp;&nbsp;</font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">OCI_DEFAULT</font><font color="#007700">);<br />&nbsp;&nbsp;echo </font><font color="#0000BB">$conn </font><font color="#007700">. </font><font color="#DD0000">"----selecting\n\n"</font><font color="#007700">;<br />&nbsp;&nbsp;while (</font><font color="#0000BB">oci_fetch</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#0000BB">$conn </font><font color="#007700">. </font><font color="#DD0000">" &lt;" </font><font color="#007700">. </font><font color="#0000BB">oci_result</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#DD0000">"TEST"</font><font color="#007700">) . </font><font color="#DD0000">"&gt;\n\n"</font><font color="#007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;echo </font><font color="#0000BB">$conn </font><font color="#007700">. </font><font color="#DD0000">"----done\n\n"</font><font color="#007700">;<br />}<br /><br /></font><font color="#0000BB">create_table</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /></font><font color="#0000BB">insert_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /><br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);<br /><br /></font><font color="#0000BB">rollback</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /><br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);<br /><br /></font><font color="#0000BB">insert_data</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);<br /></font><font color="#0000BB">commit</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);<br /><br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /><br /></font><font color="#0000BB">delete_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);<br /></font><font color="#0000BB">commit</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /><br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);<br /><br /></font><font color="#0000BB">drop_table</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);<br />echo </font><font color="#DD0000">"&lt;/pre&gt;&lt;/html&gt;"</font><font color="#007700">;<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN153785"
></A
><H2
>Notas</H2
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
    If you're using PHP with Oracle Instant Client, you can use easy connect
    naming method described here:
    <A
HREF="http://download-west.oracle.com/docs/cd/B12037_01/network.101/b10775/naming.htm#i498306"
TARGET="_top"
>http://download-west.oracle.com/docs/cd/B12037_01/network.101/b10775/naming.htm#i498306</A
>.
    Basically this means you can specify "//db_host[:port]/database_name"
    as database name. But if you want to use the old way of naming you
    <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>must</I
></SPAN
> set either <TT
CLASS="constant"
><B
>ORACLE_HOME</B
></TT
> or
    <TT
CLASS="constant"
><B
>TNS_ADMIN</B
></TT
>.
   </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
    In PHP versions before 5.0.0 you must use <A
HREF="function.ocinlogon.html"
><B
CLASS="function"
>ocinlogon()</B
></A
> instead.
    This name still can be used, it was left as alias of
    <B
CLASS="function"
>oci_new_connect()</B
> for downwards compatability.
    This, however, is deprecated and not recommended.
   </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN153797"
></A
><H2
>Veja também</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.oci-connect.html"
><B
CLASS="function"
>oci_connect()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.oci-pconnect.html"
><B
CLASS="function"
>oci_pconnect()</B
></A
></TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.oci-new-collection.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Principal</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.oci-new-cursor.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>oci_new_collection</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.oci8.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>oci_new_cursor</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>