<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >PostgreSQL</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="Referência das Funções" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="sql_regcase" HREF="function.sql-regcase.html"><LINK REL="NEXT" TITLE="pg_affected_rows" HREF="function.pg-affected-rows.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" 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.sql-regcase.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.pg-affected-rows.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.pgsql" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >CXXVII. PostgreSQL</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN179879" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.intro" >Introdução</A ></H1 ><P > O banco de dados PostgreSQL é um produto de código aberto e disponível gratuitamente. O Postgres, desenvolvido originalmente no Departamento de Ciência de Computação da Universidade de Berkeley, foi pioneiro em muitos dos conceitos objeto-relacionais que agora estão disponíveis em alguns bancos de dados comerciais. Fornece suporte a linguagem SQL92/SQL99, integridade de transações e extensibilidade de tipos. O PostgreSQL é um descendente com código aberto do código original desenvolvido em Berkeley. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.requirements" >Dependências</A ></H1 ><P > Para usar usar as funções para PostgreSQL, você precisa do PostgreSQL 6.5 ou superior e PostgreSQL 7.0 ou superior para habilitar todos os recursos deste módulo. PostgreSQL suporta inúmeros tipos de codificação de caracteres incluindo a codificação de caracteres multibyte. A versão mais atual e mais informações sobre PostgreSQL estão disponíveis em <A HREF="http://www.postgresql.org/" TARGET="_top" >http://www.postgresql.org/</A > e <A HREF="http://techdocs.postgresql.org/" TARGET="_top" >http://techdocs.postgresql.org/</A >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.installation" >Instalação</A ></H1 ><P > Para habilitar o módulo de funções para PostgreSQL, a opção de configuração <CODE CLASS="option" >--with-pgsql[=DIR]</CODE > deve ser usada no momento da compilação do PHP. Se o módulo PostgreSQL estiver disponível como objeto compartilhado, poderá ser carregado usando a diretiva <A HREF="ini.core.html#ini.extension" >extension</A > no <TT CLASS="filename" >php.ini</TT > ou a função <A HREF="function.dl.html" ><B CLASS="function" >dl()</B ></A >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.configuration" >Configurações em execução</A ></H1 ><P > O comportamento dessas funções podem ser modificado pelas configurações do <TT CLASS="filename" >php.ini</TT >. </P ><P > <DIV CLASS="table" ><A NAME="AEN179900" ></A ><P ><B >Tabela 1. Opções de configuração do PostgreSQL</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Nome</TH ><TH >Padrão</TH ><TH >Alterável</TH ></TR ></THEAD ><TBODY ><TR ><TD >pgsql.allow_persistent</TD ><TD >"1"</TD ><TD >PHP_INI_SYSTEM</TD ></TR ><TR ><TD >pgsql.max_persistent</TD ><TD >"-1"</TD ><TD >PHP_INI_SYSTEM</TD ></TR ><TR ><TD >pgsql.max_links</TD ><TD >"-1"</TD ><TD >PHP_INI_SYSTEM</TD ></TR ><TR ><TD >pgsql.auto_reset_persistent</TD ><TD >"0"</TD ><TD >PHP_INI_SYSTEM</TD ></TR ><TR ><TD >pgsql.ignore_notice</TD ><TD >"0"</TD ><TD >PHP_INI_ALL</TD ></TR ><TR ><TD >pgsql.log_notice</TD ><TD >"0"</TD ><TD >PHP_INI_ALL</TD ></TR ></TBODY ></TABLE ></DIV > Para mais detalhes e definições das constantes PHP_INI_* veja <A HREF="function.ini-set.html" ><B CLASS="function" >ini_set()</B ></A >. </P ><P >Breve descrição das diretivas de configuração.</P ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.pgsql.allow-persistent" ></A ><CODE CLASS="parameter" >pgsql.allow_persistent</CODE > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > Se quer ou não permitir conexões persistentes com o PostgreSQL. </P ></DD ><DT ><A NAME="ini.pgsql.max-persistent" ></A ><CODE CLASS="parameter" >pgsql.max_persistent</CODE > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > O número máximo de conexões persistentes com PostgreSQL por processo. </P ></DD ><DT ><A NAME="ini.pgsql.max-links" ></A ><CODE CLASS="parameter" >pgsql.max_links</CODE > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > O número máximo de conexões PostgreSQL por processo, incluindo as persistentes. </P ></DD ><DT ><A NAME="ini.pgsql.auto-reset-persistent" ></A ><CODE CLASS="parameter" >pgsql.auto_reset_persistent</CODE > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Detecta conexões permantentes quebradas <A HREF="function.pg-pconnect.html" ><B CLASS="function" >pg_pconnect()</B ></A >. Causa uma pequena sobrecarga. </P ></DD ><DT ><A NAME="ini.pgsql.ignore-notice" ></A ><CODE CLASS="parameter" >pgsql.ignore_notice</CODE > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Quando ignorar ou não os avisos do PostgreSQL. </P ></DD ><DT ><A NAME="ini.pgsql.log-notice" ></A ><CODE CLASS="parameter" >pgsql.log_notice</CODE > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Quando ou não realizar ou não o log de avisos do PostgreSQL. A diretiva <A HREF="ref.pgsql.html#ini.pgsql.ignore-notice" > pgsql.ignore_notice</A > deve estar em off para poder fazer o log dos avisos. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.using" >Como usar e algumas dicas</A ></H1 ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Atenção</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > Usar o módulo PostgreSQL com o PHP 4.0.6 não é recomendado devido a um bug no código de manipulação de notificações. Use o 4.1.0 ou superior. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Atenção</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > Os nomes das funções PostgreSQL serão alterados na versão 4.2.0 para confirmar os padrões de programação atuais. A maioria dos novos nomes terão sublinhados (underscore) adicionais, por exemplo, pg_lo_open(). Algumas funções foram renomeadas para uma maior consistência, por exemplo, pg_exec() mudou para pg_query(). Os nomes antigos podem ser usados na 4.2.0 e em algumas poucas outras versões após esta, mas eles serão removidos futuramente. </P ><DIV CLASS="table" ><A NAME="AEN179981" ></A ><P ><B >Tabela 2. Nomes de funções alterados</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><TBODY ><TR ><TD ><B CLASS="function" >pg_cmdtuples()</B ></TD ><TD ><A HREF="function.pg-affected-rows.html" ><B CLASS="function" >pg_affected_rows()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_errormessage()</B ></TD ><TD ><A HREF="function.pg-last-error.html" ><B CLASS="function" >pg_last_error()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_exec()</B ></TD ><TD ><A HREF="function.pg-query.html" ><B CLASS="function" >pg_query()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldname()</B ></TD ><TD ><A HREF="function.pg-field-name.html" ><B CLASS="function" >pg_field_name()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldsize()</B ></TD ><TD ><A HREF="function.pg-field-size.html" ><B CLASS="function" >pg_field_size()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldnum()</B ></TD ><TD ><A HREF="function.pg-field-num.html" ><B CLASS="function" >pg_field_num()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldprtlen()</B ></TD ><TD ><A HREF="function.pg-field-prtlen.html" ><B CLASS="function" >pg_field_prtlen()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_fieldisnull()</B ></TD ><TD ><A HREF="function.pg-field-is-null.html" ><B CLASS="function" >pg_field_is_null()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_freeresult()</B ></TD ><TD ><A HREF="function.pg-free-result.html" ><B CLASS="function" >pg_free_result()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_getlastoid()</B ></TD ><TD ><A HREF="function.pg-last-oid.html" ><B CLASS="function" >pg_last_oid()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loreadall()</B ></TD ><TD ><A HREF="function.pg-lo-read-all.html" ><B CLASS="function" >pg_lo_read_all()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_locreate()</B ></TD ><TD ><A HREF="function.pg-lo-create.html" ><B CLASS="function" >pg_lo_create()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_lounlink()</B ></TD ><TD ><A HREF="function.pg-lo-unlink.html" ><B CLASS="function" >pg_lo_unlink()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loopen()</B ></TD ><TD ><A HREF="function.pg-lo-unlink.html" ><B CLASS="function" >pg_lo_unlink()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loclose()</B ></TD ><TD ><A HREF="function.pg-lo-close.html" ><B CLASS="function" >pg_lo_close()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loread()</B ></TD ><TD ><A HREF="function.pg-lo-read.html" ><B CLASS="function" >pg_lo_read()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_lowrite()</B ></TD ><TD ><A HREF="function.pg-lo-write.html" ><B CLASS="function" >pg_lo_write()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loimport()</B ></TD ><TD ><A HREF="function.pg-lo-import.html" ><B CLASS="function" >pg_lo_import()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_loexport()</B ></TD ><TD ><A HREF="function.pg-lo-export.html" ><B CLASS="function" >pg_lo_export()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_numrows()</B ></TD ><TD ><A HREF="function.pg-num-rows.html" ><B CLASS="function" >pg_num_rows()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_numfields()</B ></TD ><TD ><A HREF="function.pg-num-fields.html" ><B CLASS="function" >pg_num_fields()</B ></A ></TD ></TR ><TR ><TD ><B CLASS="function" >pg_result()</B ></TD ><TD ><A HREF="function.pg-fetch-result.html" ><B CLASS="function" >pg_fetch_result()</B ></A ></TD ></TR ></TBODY ></TABLE ></DIV ><P > A antiga sintaxe <A HREF="function.pg-connect.html" ><B CLASS="function" >pg_connect()</B ></A >/<A HREF="function.pg-pconnect.html" ><B CLASS="function" >pg_pconnect()</B ></A > ficará obsoleta para suportar conexões assíncronas no futuro. Por favor, use a string de conexão para <A HREF="function.pg-connect.html" ><B CLASS="function" >pg_connect()</B ></A > e <A HREF="function.pg-pconnect.html" ><B CLASS="function" >pg_pconnect()</B ></A >. </P ></TD ></TR ></TABLE ></DIV ><P > Nem todas as funções são suportadas por todas as compilações. Isso vai depender da versão da libpq (A interface cliente em C para PostgreSQL) e como esta foi compilada. Se há alguma função ausente, é porque a libpq não suporta a característica exigida por esta função. </P ><P > Também é importante que você use uma versão da libpq mais nova do que a que o servidor exige. Se você usar uma versão mais antiga do que a que o servidor espera, você poderá ter problemas. </P ><P > Desde a versão 6.3 (03/02/1998), o PostgreSQL usa sockets de domínio unix por padrão. A porta TCP não ficará aberta por padrão. Uma tabela é mostrada abaixo descrevendo essas novas possibilidades de conexão. Este socket será encontrado em <TT CLASS="filename" >/tmp/.s.PGSQL.5432</TT >. Esta opção pode ser habilitada com o parâmetro '-i' para o <B CLASS="command" >postmaster</B > e seu significado é: "escute em sockets TCP/IP assim como em sockets de domínio Unix". <DIV CLASS="table" ><A NAME="AEN180105" ></A ><P ><B >Tabela 3. Postmaster e PHP</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Postmaster</TH ><TH >PHP</TH ><TH >Status</TH ></TR ></THEAD ><TBODY ><TR ><TD >postmaster &</TD ><TD >pg_connect("dbname=MyDbName");</TD ><TD >OK</TD ></TR ><TR ><TD >postmaster -i &</TD ><TD >pg_connect("dbname=MyDbName");</TD ><TD >OK</TD ></TR ><TR ><TD >postmaster &</TD ><TD >pg_connect("host=localhost dbname=MyDbName");</TD ><TD > Unable to connect to PostgreSQL server: connectDB() failed: Is the postmaster running and accepting TCP/IP (with -i) connection at 'localhost' on port '5432'? in /path/to/file.php on line 20. </TD ></TR ><TR ><TD >postmaster -i &</TD ><TD >pg_connect("host=localhost dbname=MyDbName");</TD ><TD >OK</TD ></TR ></TBODY ></TABLE ></DIV > </P ><P > Uma conexão com o servidor PostgreSQL pode ser estabelecida com os seguintes pares de valores definidos na string de comando: <B CLASS="command" >$conn = pg_connect("host=seuHost port=suaPorta tty=seuTTY options=suasOpcoes dbname=seuDB user=seuUsuario password=suaSenha"); </B > </P ><P > A sintaxe anterior: <B CLASS="command" > $conn = pg_connect ("host", "porta", "opcoes", "tty", "nomebd") </B > ficará obsoleta. </P ><P > Variáveis de ambiente afetam o comportamento do servidor/cliente PostgreSQL. Por exemplo, o módulo PostgreSQL irá procurar pela variável de ambiente PGHOST quando o nome de host é omitido na string de conexão. As variáveis de ambiente suportadas variam de versão para versão. Vide o Manual de Programador do PostgreSQL (Programmer´s Manual, na seção libpq - Enviroment Variables) para maiores detalhes. </P ><P > Certifique-se que você definiu as variáveis de ambiente para o usuário apropriado. Use <TT CLASS="literal" >$_ENV</TT > ou <A HREF="function.getenv.html" ><B CLASS="function" >getenv()</B ></A > para verificar se as variáveis de ambiente estão disponíveis para o processo atual. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN180138" ></A ><P ><B >Exemplo 1. Definindo os parâmetros padrão</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >PGHOST=psgql.example.com PGPORT=7890 PGDATABASE=web-system PGUSER=web-user PGPASSWORD=secret PGDATESTYLE=ISO PGTZ=JST PGCLIENTENCODING=EUC-JP export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD PGDATESTYLE PGTZ PGCLIENTENCODING</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.constants" >Constantes pré-definidas</A ></H1 ><P > As contantes abaixo são definidas por esta extensão e somente estarão disponíveis quando a extensão foi compilada com o PHP ou carregada dinamicamente durante a execução. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >PGSQL_ASSOC</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_NUM</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_BOTH</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_CONNECTION_BAD</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_CONNECTION_OK</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_SEEK_SET</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_SEEK_CUR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_SEEK_END</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_ESCAPE_STRING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_ESCAPE_BYTEA</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_EMPTY_QUERY</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_COMMAND_OK</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_TUPLES_OK</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_COPY_OUT</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_COPY_IN</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_BAD_RESPONSE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_NONFATAL_ERROR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >PGSQL_FATAL_ERROR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="pgsql.examples" >Exemplos</A ></H1 ><P > A partir do PostgreSQL 7.1.0, você pode armazenar até 1GB dentro de um campo do tipo texto. Em versões mais antigas, isto era limitado ao tamanho do bloco (o padrão era 8KB e o máximo era 32KB, definido em tempo de compilação). </P ><P > Para usar a interface de objetos grandes (large objects), é exigido que se encapsule as funções de objetos grandes em um bloco de transação. Um bloco de transação inicia-se com a declaração SQL <B CLASS="command" >BEGIN</B > e, se a transação for válida, termina com <B CLASS="command" >COMMIT</B > ou <B CLASS="command" >END</B >. Se a transação falhar, ela deve ser fechada com <B CLASS="command" >ROLLBACK</B > ou <B CLASS="command" >ABORT</B >. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN180262" ></A ><P ><B >Exemplo 2. Usando Objetos Grandes (large objects)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /> $database </font><font color="#007700">= </font><font color="#0000BB">pg_connect </font><font color="#007700">(</font><font color="#DD0000">"dbname=jacarta"</font><font color="#007700">);<br /> </font><font color="#0000BB">pg_query </font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#DD0000">"begin"</font><font color="#007700">);<br /> </font><font color="#0000BB">$oid </font><font color="#007700">= </font><font color="#0000BB">pg_lo_create </font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">);<br /> echo </font><font color="#DD0000">"$oid</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br /> </font><font color="#0000BB">$handle </font><font color="#007700">= </font><font color="#0000BB">pg_lo_open </font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#0000BB">$oid</font><font color="#007700">, </font><font color="#DD0000">"w"</font><font color="#007700">);<br /> echo </font><font color="#DD0000">"$handle</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br /> </font><font color="#0000BB">pg_lo_write </font><font color="#007700">(</font><font color="#0000BB">$handle</font><font color="#007700">, </font><font color="#DD0000">"large object data"</font><font color="#007700">);<br /> </font><font color="#0000BB">pg_lo_close </font><font color="#007700">(</font><font color="#0000BB">$handle</font><font color="#007700">);<br /> </font><font color="#0000BB">pg_query </font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#DD0000">"commit"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > Você não deve fechar a conexão com o servidor PostgreSQL antes de fechar o objeto grande. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Índice</B ></DT ><DT ><A HREF="function.pg-affected-rows.html" >pg_affected_rows</A > -- Retorna o número de registros afetados (linhas)</DT ><DT ><A HREF="function.pg-cancel-query.html" >pg_cancel_query</A > -- Cancela uma consulta (query) assíncrona </DT ><DT ><A HREF="function.pg-client-encoding.html" >pg_client_encoding</A > -- Retorna a codificação do cliente </DT ><DT ><A HREF="function.pg-close.html" >pg_close</A > -- Fecha uma conexão PostgreSQL</DT ><DT ><A HREF="function.pg-connect.html" >pg_connect</A > -- Abre uma conexão PostgreSQL</DT ><DT ><A HREF="function.pg-connection-busy.html" >pg_connection_busy</A > -- Verifica se a conexão está ocupada ou não </DT ><DT ><A HREF="function.pg-connection-reset.html" >pg_connection_reset</A > -- Reinicia uma conexão (reconecta) </DT ><DT ><A HREF="function.pg-connection-status.html" >pg_connection_status</A > -- Retorna o status da conexão </DT ><DT ><A HREF="function.pg-convert.html" >pg_convert</A > -- Converte os valores de um array associativo em uma declaração SQL apropriada. </DT ><DT ><A HREF="function.pg-copy-from.html" >pg_copy_from</A > -- Insere registros em uma tabela a partir de um array </DT ><DT ><A HREF="function.pg-copy-to.html" >pg_copy_to</A > -- Copia uma tabela em um array </DT ><DT ><A HREF="function.pg-dbname.html" >pg_dbname</A > -- Retorna o nome do banco de dados</DT ><DT ><A HREF="function.pg-delete.html" >pg_delete</A > -- Remove registros. </DT ><DT ><A HREF="function.pg-end-copy.html" >pg_end_copy</A > -- Sincroniza com o backend PostgreSQL</DT ><DT ><A HREF="function.pg-escape-bytea.html" >pg_escape_bytea</A > -- Gera binários para o tipo bytea </DT ><DT ><A HREF="function.pg-escape-string.html" >pg_escape_string</A > -- Gera string para o tipo text/char </DT ><DT ><A HREF="function.pg-execute.html" >pg_execute</A > -- Sends a request to execute a prepared statement with given parameters, and waits for the result.</DT ><DT ><A HREF="function.pg-fetch-all-columns.html" >pg_fetch_all_columns</A > -- Fetches all rows in a particular result column as an array</DT ><DT ><A HREF="function.pg-fetch-all.html" >pg_fetch_all</A > -- Retorna todas as linhas (registros) como um array</DT ><DT ><A HREF="function.pg-fetch-array.html" >pg_fetch_array</A > -- Retorna uma linha (registro) como um array</DT ><DT ><A HREF="function.pg-fetch-assoc.html" >pg_fetch_assoc</A > -- Retorna uma linha (registro) como uma matriz associativa</DT ><DT ><A HREF="function.pg-fetch-object.html" >pg_fetch_object</A > -- Retorna uma linha (registro) como um objeto</DT ><DT ><A HREF="function.pg-fetch-result.html" >pg_fetch_result</A > -- Retorna valores a partir de um recurso (resource) de resultado</DT ><DT ><A HREF="function.pg-fetch-row.html" >pg_fetch_row</A > -- Retorna uma linha como um array enumerado</DT ><DT ><A HREF="function.pg-field-is-null.html" >pg_field_is_null</A > -- Testa se o campo é <TT CLASS="constant" ><B >NULL</B ></TT ></DT ><DT ><A HREF="function.pg-field-name.html" >pg_field_name</A > -- Retorna o nome de um campo</DT ><DT ><A HREF="function.pg-field-num.html" >pg_field_num</A > -- Retorna o número do campo referido</DT ><DT ><A HREF="function.pg-field-prtlen.html" >pg_field_prtlen</A > -- Retorna o comprimento impresso</DT ><DT ><A HREF="function.pg-field-size.html" >pg_field_size</A > -- Retorna o tamanho de armazenamento interno de um campo </DT ><DT ><A HREF="function.pg-field-table.html" >pg_field_table</A > -- Returns the name or oid of the tables field</DT ><DT ><A HREF="function.pg-field-type-oid.html" >pg_field_type_oid</A > -- Returns the type ID (OID) for the corresponding field number </DT ><DT ><A HREF="function.pg-field-type.html" >pg_field_type</A > -- Retorna o nome do tipo para o campo de nome correspondente </DT ><DT ><A HREF="function.pg-free-result.html" >pg_free_result</A > -- Libera a memória usada pelo resultado</DT ><DT ><A HREF="function.pg-get-notify.html" >pg_get_notify</A > -- Gets SQL NOTIFY message</DT ><DT ><A HREF="function.pg-get-pid.html" >pg_get_pid</A > -- Gets the backend's process ID</DT ><DT ><A HREF="function.pg-get-result.html" >pg_get_result</A > -- Retorna o resultado de uma consulta (query) assíncrona </DT ><DT ><A HREF="function.pg-host.html" >pg_host</A > -- Retorna o nome da máquina associada a uma conexão </DT ><DT ><A HREF="function.pg-insert.html" >pg_insert</A > -- Insere um array na tabela </DT ><DT ><A HREF="function.pg-last-error.html" >pg_last_error</A > -- Retorna a string da última mensagem de erro de uma conexão</DT ><DT ><A HREF="function.pg-last-notice.html" >pg_last_notice</A > -- Retorna a última notificação do servidor PostgreSQL </DT ><DT ><A HREF="function.pg-last-oid.html" >pg_last_oid</A > -- Retorna o último oid do objeto</DT ><DT ><A HREF="function.pg-lo-close.html" >pg_lo_close</A > -- Fecha um objeto grande (large object)</DT ><DT ><A HREF="function.pg-lo-create.html" >pg_lo_create</A > -- Cria um objeto grande (large object)</DT ><DT ><A HREF="function.pg-lo-export.html" >pg_lo_export</A > -- Exporta um objeto grande (large object) para um arquivo</DT ><DT ><A HREF="function.pg-lo-import.html" >pg_lo_import</A > -- Importa um objeto grande (large object) a partir de um arquivo</DT ><DT ><A HREF="function.pg-lo-open.html" >pg_lo_open</A > -- Abre um objeto grande (large object)</DT ><DT ><A HREF="function.pg-lo-read-all.html" >pg_lo_read_all</A > -- Lê um objeto grande (large object) inteiro e o envia diretamente para o navegador </DT ><DT ><A HREF="function.pg-lo-read.html" >pg_lo_read</A > -- Lê um objeto grande (large object)</DT ><DT ><A HREF="function.pg-lo-seek.html" >pg_lo_seek</A > -- Procura uma posição em um objeto grande (large object) </DT ><DT ><A HREF="function.pg-lo-tell.html" >pg_lo_tell</A > -- Retorna a posição atual de um objeto grande (large object) </DT ><DT ><A HREF="function.pg-lo-unlink.html" >pg_lo_unlink</A > -- Remove um objeto grande (large object)</DT ><DT ><A HREF="function.pg-lo-write.html" >pg_lo_write</A > -- Escreve em um objeto grande (large object)</DT ><DT ><A HREF="function.pg-meta-data.html" >pg_meta_data</A > -- Retorna os metadados da tabela. </DT ><DT ><A HREF="function.pg-num-fields.html" >pg_num_fields</A > -- Retorna o número de campos</DT ><DT ><A HREF="function.pg-num-rows.html" >pg_num_rows</A > -- Retorna o número de linhas</DT ><DT ><A HREF="function.pg-options.html" >pg_options</A > -- Retorna as opções associadas com a conexão</DT ><DT ><A HREF="function.pg-parameter-status.html" >pg_parameter_status</A > -- Looks up a current parameter setting of the server.</DT ><DT ><A HREF="function.pg-pconnect.html" >pg_pconnect</A > -- Abre uma conexão PostgreSQL persistente</DT ><DT ><A HREF="function.pg-ping.html" >pg_ping</A > -- Faz um ping na conexão com o banco de dados</DT ><DT ><A HREF="function.pg-port.html" >pg_port</A > -- Retorna o número da porta associada com a conexão. </DT ><DT ><A HREF="function.pg-prepare.html" >pg_prepare</A > -- Submits a request to create a prepared statement with the given parameters, and waits for completion.</DT ><DT ><A HREF="function.pg-put-line.html" >pg_put_line</A > -- Envia uma string terminada em NULL para o backend PostgreSQL</DT ><DT ><A HREF="function.pg-query-params.html" >pg_query_params</A > -- Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text.</DT ><DT ><A HREF="function.pg-query.html" >pg_query</A > -- Executa uma consulta (query)</DT ><DT ><A HREF="function.pg-result-error-field.html" >pg_result_error_field</A > -- Returns an individual field of an error report.</DT ><DT ><A HREF="function.pg-result-error.html" >pg_result_error</A > -- Retorna a mensagem de erro associada a um resultado </DT ><DT ><A HREF="function.pg-result-seek.html" >pg_result_seek</A > -- Altera a posição do ponteiro interno de um recurso (resource) de resultado</DT ><DT ><A HREF="function.pg-result-status.html" >pg_result_status</A > -- Retorna o status do resultado da consulta (query) </DT ><DT ><A HREF="function.pg-select.html" >pg_select</A > -- Seleciona registros. </DT ><DT ><A HREF="function.pg-send-execute.html" >pg_send_execute</A > -- Sends a request to execute a prepared statement with given parameters, without waiting for the result(s).</DT ><DT ><A HREF="function.pg-send-prepare.html" >pg_send_prepare</A > -- Sends a request to create a prepared statement with the given parameters, without waiting for completion.</DT ><DT ><A HREF="function.pg-send-query-params.html" >pg_send_query_params</A > -- Submits a command and separate parameters to the server without waiting for the result(s).</DT ><DT ><A HREF="function.pg-send-query.html" >pg_send_query</A > -- Envia uma consulta (query) assincrona </DT ><DT ><A HREF="function.pg-set-client-encoding.html" >pg_set_client_encoding</A > -- Define a codificação do cliente </DT ><DT ><A HREF="function.pg-set-error-verbosity.html" >pg_set_error_verbosity</A > -- Determines the verbosity of messages returned by <A HREF="function.pg-last-error.html" ><B CLASS="function" >pg_last_error()</B ></A > and <A HREF="function.pg-result-error.html" ><B CLASS="function" >pg_result_error()</B ></A >. </DT ><DT ><A HREF="function.pg-trace.html" >pg_trace</A > -- Habilita rastreamento em uma conexão PostgreSQL</DT ><DT ><A HREF="function.pg-transaction-status.html" >pg_transaction_status</A > -- Returns the current in-transaction status of the server.</DT ><DT ><A HREF="function.pg-tty.html" >pg_tty</A > -- Retorna o nome da tty associada com a conexão </DT ><DT ><A HREF="function.pg-unescape-bytea.html" >pg_unescape_bytea</A > -- Faz escape binário para o tipo bytea </DT ><DT ><A HREF="function.pg-untrace.html" >pg_untrace</A > -- Desabilita o rastreamento de uma conexão PostgreSQL</DT ><DT ><A HREF="function.pg-update.html" >pg_update</A > -- Atualiza uma tabela. </DT ><DT ><A HREF="function.pg-version.html" >pg_version</A > -- Returns an array with client, protocol and server version (when available) </DT ></DL ></DIV ></DIV ></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.sql-regcase.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.pg-affected-rows.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >sql_regcase</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >pg_affected_rows</TD ></TR ></TABLE ></DIV ></BODY ></HTML >