mirror of
https://github.com/php/doc-pl.git
synced 2026-03-24 07:02:07 +01:00
200 lines
6.7 KiB
XML
200 lines
6.7 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- EN-Revision: 39bb8a868935a56cfce438b0169e13c02c93211c Maintainer: sobak Status: ready -->
|
|
<!-- $Revision$-->
|
|
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.80 -->
|
|
<!-- CREDITS: garbus, jarek -->
|
|
<refentry xml:id='function.pg-insert' xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pg_insert</refname>
|
|
<refpurpose>
|
|
Wstawia tablicę do tabeli
|
|
</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>PgSql\Result</type><type>string</type><type>bool</type></type><methodname>pg_insert</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 choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>PGSQL_DML_EXEC</constant></initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>pg_insert</function> wstawia wartości parametru <parameter>values</parameter>
|
|
do tabeli określonej przez parametr <parameter>table_name</parameter>.
|
|
</para>
|
|
<para>
|
|
Jeśli parametr <parameter>flags</parameter> jest określony,
|
|
to do warunków podanych <parameter>conditions</parameter> stosowana jest funkcja <function>pg_convert</function>
|
|
z określonymi flagami.
|
|
</para>
|
|
<para>
|
|
Domyślnie <function>pg_insert</function> przekazuje surowe wartości.
|
|
Wartości muszą mieć dodane znaki ucieczki lub należy podać flagę <constant>PGSQL_DML_ESCAPE</constant>
|
|
w parametrze <parameter>flags</parameter>.
|
|
<constant>PGSQL_DML_ESCAPE</constant> dodaje cudzysłowy i znaki ucieczki do parametrów/identyfikatorów.
|
|
W związku z tym nazwy tabeli i kolumn stają się wrażliwe na wielkość znaków.
|
|
</para>
|
|
<para>
|
|
Note that neither escape nor prepared query can protect LIKE query,
|
|
JSON, Array, Regex, etc. These parameters should be handled
|
|
according to their contexts. i.e. Escape/validate values.
|
|
</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>
|
|
Nazwa tabeli, do której mają zostać dodane wiersze. Tabela <parameter>table_name</parameter> musi mieć
|
|
przynajmniej tyle kolumn, ile elementów ma tablica <parameter>values</parameter>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>values</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Tablica (ang. <type>array</type>), której klucze to nazwy pól w tabeli <parameter>table_name</parameter>,
|
|
oraz której wartościami są wartości tych pól, które mają zostać wpisane.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>flags</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Dowolna kombinacja dowolnej ilości parametrów: <constant>PGSQL_CONV_OPTS</constant>,
|
|
<constant>PGSQL_DML_NO_CONV</constant>,
|
|
<constant>PGSQL_DML_ESCAPE</constant>,
|
|
<constant>PGSQL_DML_EXEC</constant>,
|
|
<constant>PGSQL_DML_ASYNC</constant> oraz
|
|
<constant>PGSQL_DML_STRING</constant>. Gdy <constant>PGSQL_DML_STRING</constant> jest zawarty w parametrze
|
|
<parameter>opcje</parameter>, zwrócony zostanie łańcuch zapytania. Kiedy ustawione jest
|
|
<constant>PGSQL_DML_NO_CONV</constant> lub <constant>PGSQL_DML_ESCAPE</constant>, funkcja nie wykonuje <function>pg_convert</function>
|
|
wewnętrznie.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success;. Zwraca łańcuch (ang. <type>string</type>) jeśli <constant>PGSQL_DML_STRING</constant> zostało przekazane
|
|
poprzez parametr <parameter>flags</parameter>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Gdy określona tabela jest nieprawidłowa, rzucany jest <classname>ValueError</classname>.
|
|
</para>
|
|
<para>
|
|
Jeśli wartość lub typ pola nie pasuje poprawnie do typu PostreSQL,
|
|
to rzucany jest <classname>ValueError</classname> lub <classname>TypeError</classname>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.3.0</entry>
|
|
<entry>
|
|
Rzuca teraz błąd <classname>ValueError</classname> jeśli podana tabela jest niepoprawna;
|
|
wcześniej emitowane było ostrzeżenie (<constant>E_WARNING</constant>).
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>8.3.0</entry>
|
|
<entry>
|
|
Funkcja rzuca teraz błąd <classname>ValueError</classname> lub <classname>TypeError</classname>
|
|
jeśli wartość lub typ pola nie psuje poprawnie do typu PostreSQL;
|
|
wcześniej emitowane było ostrzeżenie (<constant>E_WARNING</constant>).
|
|
</entry>
|
|
</row>
|
|
&pgsql.changelog.return-result-object;
|
|
&pgsql.changelog.connection-object;
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Przykład użycia <function>pg_insert</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$dbconn = pg_connect('dbname=foo');
|
|
// This is safe somewhat, since all values are escaped.
|
|
// However PostgreSQL supports JSON/Array. These are not
|
|
// safe by neither escape nor prepared query.
|
|
$res = pg_insert($dbconn, 'post_log', $_POST, PGSQL_DML_ESCAPE);
|
|
if ($res) {
|
|
echo "Dane z tablicy POST zapisane pomyślnie\n";
|
|
} else {
|
|
echo "Użytkownik musiał wysłać złe dane\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
|
|
-->
|