mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-25 23:52:13 +01:00
211 lines
7.2 KiB
XML
211 lines
7.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 18aa2012f6fa1e5b09733147e02911d16e06d4a1 Maintainer: leonardolara Status: ready --><!-- CREDITS: fernandowobeto -->
|
|
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.80 -->
|
|
<refentry xml:id="function.pg-select" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pg_select</refname>
|
|
<refpurpose>
|
|
Seleciona registros
|
|
</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>array</type><type>string</type><type>false</type></type><methodname>pg_select</methodname>
|
|
<methodparam><type>PgSql\Connection</type><parameter>connection</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>table_name</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>conditions</parameter><initializer>[]</initializer></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>PGSQL_DML_EXEC</constant></initializer></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer><constant>PGSQL_ASSOC</constant></initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>pg_select</function> seleciona registros especificados por
|
|
<parameter>conditions</parameter> que tem
|
|
<literal>field=>value</literal>. Para uma consulta bem-sucedida, ele retorna um
|
|
array contendo todos os registros e campos que correspondem à condição
|
|
especificada por <parameter>conditions</parameter>.
|
|
</para>
|
|
<para>
|
|
Se <parameter>flags</parameter> estiver definido,
|
|
<function>pg_convert</function> será aplicado às
|
|
<parameter>conditions</parameter> com as opções (flags) especificadas.
|
|
</para>
|
|
<para>
|
|
Se <parameter>mode</parameter> for definido,
|
|
o valor de retorno estará na forma de um array
|
|
com <constant>PGSQL_NUM</constant>, um array associativo
|
|
com <constant>PGSQL_ASSOC</constant> (padrão) ou ambos
|
|
com <constant>PGSQL_BOTH</constant>.
|
|
</para>
|
|
<para>
|
|
Por padrão, <function>pg_select</function> passa valores brutos. Os valores
|
|
devem ter escape ou a opção PGSQL_DML_ESCAPE deve ser
|
|
especificada. PGSQL_DML_ESCAPE cita e escapa
|
|
parâmetros/identificadores. Portanto, os nomes de tabelas/colunas tornaram-se
|
|
sensíveis a maiúsculas e minúsculas.
|
|
</para>
|
|
<para>
|
|
Observe que nem o escape nem a consulta preparada podem proteger a consulta LIKE,
|
|
JSON, Array, Regex, etc. Esses parâmetros devem ser tratados
|
|
de acordo com seus contextos. ou seja, escapar/validar valores.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>connection</parameter></term>
|
|
<listitem>
|
|
&pgsql.parameter.connection;
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>table_name</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Nome da tabela da qual selecionar linhas.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>conditions</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Um <type>array</type> cujas chaves são nomes de campos na tabela <parameter>table_name</parameter>
|
|
e cujos valores são as condições que uma linha deve atender para ser recuperada.
|
|
A partir do PHP 8.4.0, quando um array vazio for fornecido, nenhuma condição será aplicada.
|
|
Anteriormente, a função falhava com um argumento <parameter>conditions</parameter> vazio.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>flags</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Qualquer número de <constant>PGSQL_CONV_FORCE_NULL</constant>,
|
|
<constant>PGSQL_DML_NO_CONV</constant>,
|
|
<constant>PGSQL_DML_ESCAPE</constant>,
|
|
<constant>PGSQL_DML_EXEC</constant>,
|
|
<constant>PGSQL_DML_ASYNC</constant> ou
|
|
<constant>PGSQL_DML_STRING</constant> combinado. Se <constant>PGSQL_DML_STRING</constant> fizer parte dos
|
|
<parameter>flags</parameter> então a string de consulta será retornada. Quando <constant>PGSQL_DML_NO_CONV</constant>
|
|
ou <constant>PGSQL_DML_ESCAPE</constant> está definido, ele não chama <function>pg_convert</function> internamente.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>mode</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Qualquer número de <constant>PGSQL_ASSOC</constant>,
|
|
<constant>PGSQL_NUM</constant> ou
|
|
<constant>PGSQL_BOTH</constant>
|
|
Se <constant>PGSQL_ASSOC</constant> for definido o valor de retorno será um <type>array</type> associativo,
|
|
com <constant>PGSQL_NUM</constant> o valor de retorno será um <type>array</type> , e
|
|
com <constant>PGSQL_BOTH</constant> o valor de retorno será um
|
|
<type>array</type> associativo e indexado numericamente.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna <type>string</type> se <constant>PGSQL_DML_STRING</constant> for passado
|
|
via <parameter>flags</parameter>, caso contrário, retorna um <type>array</type> em caso de sucesso, &return.falseforfailure;.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.4.0</entry>
|
|
<entry>
|
|
<parameter>conditions</parameter> agora é opcional.
|
|
</entry>
|
|
</row>
|
|
&pgsql.changelog.connection-object;
|
|
<row>
|
|
<entry>7.1.0</entry>
|
|
<entry>
|
|
O parâmetro <parameter>mode</parameter> foi adicionado.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <function>pg_select</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$db = pg_connect('dbname=foo');
|
|
// Isso é um tanto seguro, já que todos os valores têm escape.
|
|
// No entanto, o PostgreSQL suporta JSON/Array. Estes não são
|
|
// seguros nem por escape nem por consulta preparada.
|
|
$rec = pg_select($db, 'post_log', $_POST, PG_DML_ESCAPE);
|
|
if ($rec) {
|
|
echo "Registros selecionados\n";
|
|
var_dump($rec);
|
|
} else {
|
|
echo "Usuário deve ter enviado entradas erradas\n";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pg_convert</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
|
|
-->
|