mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-24 07:02:09 +01:00
* inclusão dos arquivos originais com revisão atualizada * tradução em reference/pgsql/functions * removida tradução equivocada em tags * removida tradução indevida de tag * Delete reference/pgsql/functions/pg-connection-busy.old * Delete reference/pgsql/functions/pg-connection-reset.old * Delete reference/pgsql/functions/pg-convert.old * Delete reference/pgsql/functions/pg-fetch-assoc.old * Delete reference/pgsql/functions/pg-field-name.old * Delete reference/pgsql/functions/pg-meta-data.old * Delete reference/pgsql/functions/pg-send-query.old * Update pg-field-num.xml * Update pg-unescape-bytea.xml * Update pg-escape-bytea.xml * Update pg-convert.xml * Update pg-result-status.xml * Update pg-pconnect.xml * Update pg-parameter-status.xml * Update pg-set-client-encoding.xml * tradução de pg-affected-rows
199 lines
5.7 KiB
XML
199 lines
5.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: c2eca73ef79ebe78cebb34053e41b565af504c4f Maintainer: fernandowobeto Status: ready --><!-- CREDITS: fernandowobeto -->
|
|
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.2 -->
|
|
<refentry xml:id="function.pg-query" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pg_query</refname>
|
|
<refpurpose>Executa uma consulta</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>PgSql\Result</type><type>false</type></type><methodname>pg_query</methodname>
|
|
<methodparam choice="opt"><type>PgSql\Connection</type><parameter>connection</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>query</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>pg_query</function> executa a <parameter>query</parameter>
|
|
na <parameter>connection</parameter> do banco de dados especificado.
|
|
<function>pg_query_params</function> deve ser preferido
|
|
na maioria dos casos.
|
|
</para>
|
|
<para>
|
|
Se ocorrer um erro e &false; for retornado, os detalhes do erro poderão
|
|
ser recuperados usando a função <function>pg_last_error</function>
|
|
se a conexão for válida.
|
|
</para>
|
|
<para>
|
|
<note>
|
|
<simpara>
|
|
Embora <parameter>connection</parameter> possa ser omitido, isso
|
|
não é recomendado, pois pode ser a causa de erros difíceis de encontrar
|
|
em scripts.
|
|
</simpara>
|
|
</note>
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Esta função costumava ser chamada de <function>pg_exec</function>.
|
|
<function>pg_exec</function> ainda está disponível por motivos de
|
|
compatibilidade, mas os usuários são incentivados a usar o nome mais recente.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>connection</parameter></term>
|
|
<listitem>
|
|
&pgsql.parameter.connection-with-unspecified-default;
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>query</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
A instrução ou instruções SQL a serem executadas. Quando múltiplas instruções são passadas para a função,
|
|
elas são automaticamente executadas como uma transação, a menos que haja comandos BEGIN/COMMIT explícitos
|
|
incluídos na string de consulta. No entanto, não é recomendado usar múltiplas transações em uma chamada de função.
|
|
</para>
|
|
<warning>
|
|
<para>
|
|
A interpolação de strings de dados fornecidos pelo usuário é extremamente perigosa e
|
|
provavelmente levará a vulnerabilidades de <link linkend="security.database.sql-injection">injeção
|
|
de SQL</link>. Na maioria dos casos,
|
|
<function>pg_query_params</function> deve ser preferido, passando
|
|
valores fornecidos pelo usuário como parâmetros em vez de substituí-los
|
|
na string de consulta.
|
|
</para>
|
|
<para>
|
|
Quaisquer dados fornecidos pelo usuário substituídos diretamente em uma string de consulta devem
|
|
ser <link linkend="function.pg-escape-string">escapados corretamente</link>.
|
|
</para>
|
|
</warning>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Uma instância <classname>PgSql\Result</classname> em caso de sucesso, &return.falseforfailure;.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
&pgsql.changelog.return-result-object;
|
|
&pgsql.changelog.connection-object;
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <function>pg_query</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$conn = pg_pconnect("dbname=publisher");
|
|
if (!$conn) {
|
|
echo "Ocorreu um erro.\n";
|
|
exit;
|
|
}
|
|
|
|
$result = pg_query($conn, "SELECT author, email FROM authors");
|
|
if (!$result) {
|
|
echo "Ocorreu um erro.\n";
|
|
exit;
|
|
}
|
|
|
|
while ($row = pg_fetch_row($result)) {
|
|
echo "Autor: $row[0] E-mail: $row[1]";
|
|
echo "<br />\n";
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Usando <function>pg_query</function> com múltiplas instruções</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$conn = pg_pconnect("dbname=publisher");
|
|
|
|
// essas instruções serão executadas como uma transação
|
|
|
|
$query = "UPDATE authors SET author=UPPER(author) WHERE id=1;";
|
|
$query .= "UPDATE authors SET author=LOWER(author) WHERE id=2;";
|
|
$query .= "UPDATE authors SET author=NULL WHERE id=3;";
|
|
|
|
pg_query($conn, $query);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pg_connect</function></member>
|
|
<member><function>pg_pconnect</function></member>
|
|
<member><function>pg_fetch_array</function></member>
|
|
<member><function>pg_fetch_object</function></member>
|
|
<member><function>pg_num_rows</function></member>
|
|
<member><function>pg_affected_rows</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|