1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-26 00:32:15 +01:00
Files
archived-doc-ru/reference/pgsql/functions/pg-select.xml
2023-07-06 17:25:18 +03:00

206 lines
8.2 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 2fa74a5512c0a7d3eabe39b1060646fc32f253f5 Maintainer: aur Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.pg-select" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>pg_select</refname>
<refpurpose>
Выбирает записи из базы данных
</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><type>array</type><parameter>conditions</parameter></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> выбирает записи из базы данных,
удовлетворяющие условиям <literal>field=&gt;value</literal>, заданным
в массиве <parameter>conditions</parameter>.
</para>
<para>
Если задан параметр <parameter>flags</parameter>, то к массиву
<parameter>conditions</parameter> будет применена функция
<function>pg_convert</function> с параметрами, заданными в
качестве аргумента.
</para>
<para>
Если задан параметр <parameter>mode</parameter>,
возвращаемое значение будет в виде массива
при <constant>PGSQL_NUM</constant>, ассоциативного массива
при <constant>PGSQL_ASSOC</constant> (по умолчанию)
или и того, и другого при <constant>PGSQL_BOTH</constant>.
</para>
<para>
По умолчанию <function>pg_insert</function> передаёт необработанные значения.
Значения должны быть экранированы или опция PGSQL_DML_ESCAPE должна быть
указана. PGSQL_DML_ESCAPE заключает в кавычки и экранирует
параметры/идентификаторы. Поэтому имена таблиц/столбцов становятся
чувствительными к регистру.
</para>
<para>
Обратите внимание, что ни экранирование, ни подготовленный запрос не защитят запрос LIKE,
JSON, массив, регулярные выражения и т.д.. Эти параметры должны обрабатываться
в соответствии с их контекстами, т.е. следует экранировать/проверять значения.
</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>
Название таблицы, из которой выбираются данные.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>conditions</parameter></term>
<listitem>
<para>
Массив (<type>array</type>), ключи которого соответствуют именам колонок таблицы
<parameter>table_name</parameter>. Будут выбраны только те строки,
значения полей которых совпадут со значениями массива.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
Одна из констант <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>,
<constant>PGSQL_DML_STRING</constant> или их комбинация.
Если <parameter>flags</parameter> содержит
<constant>PGSQL_DML_STRING</constant>, функция вернёт строку. Если установлены <constant>PGSQL_DML_NO_CONV</constant>
или <constant>PGSQL_DML_ESCAPE</constant>, то функция <function>pg_convert</function> внутренне не вызывается.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>mode</parameter></term>
<listitem>
<para>
Одна из констант <constant>PGSQL_ASSOC</constant>,
<constant>PGSQL_NUM</constant> или
<constant>PGSQL_BOTH</constant>.
Если установлено значение <constant>PGSQL_ASSOC</constant>, возвращаемое значение
будет ассоциативным массивом (<type>array</type>),
при <constant>PGSQL_NUM</constant> возвращаемое значение будет массивом (<type>array</type>),
а при <constant>PGSQL_BOTH</constant> возвращаемое значение будет и ассоциативным
и числовым индексированным массивом (<type>array</type>).
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает строку (<type>string</type>), если <parameter>flags</parameter>
содержит <constant>PGSQL_DML_STRING</constant>,
в противном случае в случае успешного выполнения функция возвращает массив (<type>array</type>)&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>
&pgsql.changelog.connection-object;
<row>
<entry>7.1.0</entry>
<entry>
Добавлен параметр <parameter>mode</parameter>.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример использования <function>pg_select</function></title>
<programlisting role="php">
<![CDATA[
<?php
$db = pg_connect('dbname=foo');
// Это безопасно в некоторой степени, поскольку все значения экранируются.
// Однако PostgreSQL поддерживает JSON/массив. Для этих значений это не безопасно
// ни с через экранирование, ни с помощью подготовленного запроса.
$rec = pg_select($db, 'post_log', $_POST);
if ($rec) {
echo "Records selected\n";
var_dump($rec);
} else {
echo "Должно быть переданы неверные данные\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
-->