1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-24 15:52:13 +01:00
Files
archived-doc-ru/reference/pgsql/functions/pg-connect.xml
2025-03-02 16:57:43 +03:00

184 lines
7.7 KiB
XML
Raw Permalink 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: c2eca73ef79ebe78cebb34053e41b565af504c4f Maintainer: aur Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.pg-connect" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>pg_connect</refname>
<refpurpose>Открывает соединение с базой данных PostgreSQL</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>PgSql\Connection</type><type>false</type></type><methodname>pg_connect</methodname>
<methodparam><type>string</type><parameter>connection_string</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<para>
Функция <function>pg_connect</function> открывает соединение с базой данных
PostgreSQL на основе параметров, которые указали в строке <parameter>connection_string</parameter>.
</para>
<para>
При повторном вызове функции <function>pg_connect</function> с теми же параметрами
в строке <parameter>connection_string</parameter> функция вернёт подключение,
которое уже установили, если только в параметр <parameter>flags</parameter>
не передали флаг <constant>PGSQL_CONNECT_FORCE_NEW</constant>.
</para>
<para>
Прежний синтаксис с набором параметров —
<command>$conn = pg_connect("host", "port", "options", "tty", "dbname")</command>
устарел.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>connection_string</parameter></term>
<listitem>
<para>
Параметр <parameter>connection_string</parameter> принимает пустую строку или настройки параметров через пробел.
Каждую настройку параметра передают в форме <literal>keyword = value</literal>. Пробелы вокруг
знака равенства необязательны. Пустые значения или значения
с пробелами записывают в одинарных кавычках: <literal>keyword = 'a value'</literal>.
Одинарные кавычки и обратные слеши внутри значения
экранируют обратным слешем: \' и \\.
</para>
<para>
Функция распознаёт следующие параметры:
<parameter>host</parameter>, <parameter>hostaddr</parameter>, <parameter>port</parameter>,
<parameter>dbname</parameter> (значение по умолчанию для параметра <parameter>user</parameter>),
<parameter>user</parameter>,
<parameter>password</parameter>, <parameter>connect_timeout</parameter>,
<parameter>options</parameter>, <parameter>tty</parameter> (игнорируется), <parameter>sslmode</parameter>,
<parameter>requiressl</parameter> (устарело в связи с использованием параметра <parameter>sslmode</parameter>)
и <parameter>service</parameter>. Поддержка параметров зависит от версии СУБД PostgreSQL.
</para>
<para>
Параметр <parameter>options</parameter> устанавливает параметры командной строки, которые
вызовет сервер.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
При передаче флага <constant>PGSQL_CONNECT_FORCE_NEW</constant> функция создаёт новое соединение,
даже если строка подключения <parameter>connection_string</parameter> идентична
строке подключения, которое уже установили.
</para>
<para>
При передаче флага <constant>PGSQL_CONNECT_ASYNC</constant> функция устанавливает
асинхронное соединение. Состояние соединения
проверяют функцией <function>pg_connect_poll</function>
или <function>pg_connection_status</function>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Функция возвращает экземпляр класса <classname>PgSql\Connection</classname>,
если выполнилась успешно,&return.falseforfailure;.
</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.1.0</entry>
<entry>
Функция теперь возвращает экземпляр класса <classname>PgSql\Connection</classname>;
раньше возвращался ресурс (&resource;).
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример установки соединения функцией <function>pg_connect</function></title>
<programlisting role="php">
<![CDATA[
<?php
// Подключение к базе данных "mary"
$dbconn = pg_connect("dbname=mary");
// Подключение к базе "mary" на хосте "localhost" и порте "5432"
$dbconn2 = pg_connect("host=localhost port=5432 dbname=mary");
// Подключение к базе "mary" на хосте "sheep" с именем пользователя и паролем
$dbconn3 = pg_connect("host=sheep port=5432 dbname=mary user=lamb password=foo");
// Подключение к базе "test" на хосте "sheep" с именем пользователя и паролем
$conn_string = "host=sheep port=5432 dbname=test user=lamb password=bar";
$dbconn4 = pg_connect($conn_string);
// Подключение к базе на хосте "localhost" с передачей параметра командной строки,
// который устанавливает кодировку UTF-8
$dbconn5 = pg_connect("host=localhost options='--client_encoding=UTF8'");
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>pg_pconnect</function></member>
<member><function>pg_close</function></member>
<member><function>pg_host</function></member>
<member><function>pg_port</function></member>
<member><function>pg_tty</function></member>
<member><function>pg_options</function></member>
<member><function>pg_dbname</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
-->