Sophie

Sophie

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

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_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_commit"
HREF="function.oci-commit.html"><LINK
REL="NEXT"
TITLE="oci_define_by_name"
HREF="function.oci-define-by-name.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-commit.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-define-by-name.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.oci-connect"
></A
>oci_connect</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN151720"
></A
><P
>    (PHP 5)</P
>oci_connect&nbsp;--&nbsp;Establishes a connection to the Oracle server</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN151723"
></A
><H2
>Descrição</H2
>resource <B
CLASS="methodname"
>oci_connect</B
> ( string username, string password [, string db [, string charset [, int session_mode]]] )<BR
></BR
><P
>&#13;   Returns a connection identifier needed for most other OCI calls. 
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN151744"
></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="AEN151787"
></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="AEN151791"
></A
><H2
>Exemplos</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN151794"
></A
><P
><B
>Exemplo 1. <B
CLASS="function"
>oci_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;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_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 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">" [" </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">"]\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">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Insert a row using c1<br /></font><font color="#0000BB">insert_data</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Insert a row using c2<br /><br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Results of both inserts are returned<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">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Rollback using c1<br /><br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Both inserts have been rolled back<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">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Insert a row using c2<br /></font><font color="#0000BB">commit</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Commit using c2<br /><br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Result of c2 insert is returned<br /><br /></font><font color="#0000BB">delete_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Delete all rows in table using c1<br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// No rows returned<br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// No rows returned<br /></font><font color="#0000BB">commit</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// Commit using c1<br /><br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c1</font><font color="#007700">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// No rows returned<br /></font><font color="#0000BB">select_data</font><font color="#007700">(</font><font color="#0000BB">$c2</font><font color="#007700">);&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// No rows returned<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;"</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="AEN151798"
></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
>
    The second and subsequent calls to <B
CLASS="function"
>oci_connect()</B
>
    with the same parameters will return the connection handle returned
    from the first call. This means that queries issued against one
    handle are also applied to the other handles, because they are the
    <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>same</I
></SPAN
> handle. This behaviour is demonstrated in
    Example 1 below. If you require two handles to be transactionally
    isolated from each other, you should use
    <A
HREF="function.oci-new-connect.html"
><B
CLASS="function"
>oci_new_connect()</B
></A
> instead.
   </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.ocilogon.html"
><B
CLASS="function"
>ocilogon()</B
></A
> instead.
    This name still can be used, it was left as the alias of
    <B
CLASS="function"
>oci_connect()</B
> for downwards compatability.
    This, however, is deprecated and not recommended.
   </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN151815"
></A
><H2
>Veja também</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.oci-pconnect.html"
><B
CLASS="function"
>oci_pconnect()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.oci-new-connect.html"
><B
CLASS="function"
>oci_new_connect()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.oci-close.html"
><B
CLASS="function"
>oci_close()</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-commit.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-define-by-name.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>oci_commit</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_define_by_name</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>