mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-24 15:12:23 +01:00
180 lines
5.8 KiB
XML
180 lines
5.8 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.80 -->
|
|
<refentry xml:id="function.pg-update" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pg_update</refname>
|
|
<refpurpose>
|
|
Atualiza tabela
|
|
</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>string</type><type>bool</type></type><methodname>pg_update</methodname>
|
|
<methodparam><type>PgSql\Connection</type><parameter>connection</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>table_name</parameter></methodparam>
|
|
<methodparam><type>array</type><parameter>values</parameter></methodparam>
|
|
<methodparam><type>array</type><parameter>conditions</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>PGSQL_DML_EXEC</constant></initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>pg_update</function> atualiza registros que correspondem a
|
|
<parameter>conditions</parameter> com <parameter>values</parameter>.
|
|
</para>
|
|
<para>
|
|
Se <parameter>flags</parameter> for especificado,
|
|
<function>pg_convert</function> será aplicado aos
|
|
<parameter>values</parameter> com as opções especificadas.
|
|
</para>
|
|
<para>
|
|
Por padrão, <function>pg_update</function> passa valores brutos.
|
|
Os valores devem ser escapados ou a opção <constant>PGSQL_DML_ESCAPE</constant>
|
|
deve ser especificado em <parameter>flags</parameter>.
|
|
<constant>PGSQL_DML_ESCAPE</constant> cita e escapa parâmetros/identificadores.
|
|
Portanto, os nomes de tabelas/colunas diferenciam maiúsculas de minúsculas.
|
|
</para>
|
|
<para>
|
|
Observe que nem o escape nem a consulta preparada podem proteger consultas LIKE,
|
|
JSON, Array, Regex, etc. Estes parâmetros devem ser manipulados
|
|
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 na qual as linhas serão atualizadas.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>values</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 os valores para os quais as linhas correspondentes devem ser atualizadas.
|
|
</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 atualizada.
|
|
</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>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success; Retorna <type>string</type> se <constant>PGSQL_DML_STRING</constant> for passado
|
|
através de <parameter>flags</parameter>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
&pgsql.changelog.connection-object;
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <function>pg_update</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$db = pg_connect('dbname=foo');
|
|
$data = array('field1'=>'AA', 'field2'=>'BB');
|
|
// 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.
|
|
$res = pg_update($db, 'post_log', $_POST, $data);
|
|
if ($res) {
|
|
echo "Dados foram atualizados: $res\n";
|
|
} else {
|
|
echo "Usuário deve ter enviado dados errados\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
|
|
-->
|