1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-25 16:22:18 +01:00
Files
archived-doc-ru/reference/pgsql/functions/pg-connect.xml
Sergey Panteleev 6d43fd64d7 Исправление форматирования
[skip-spellcheck]
[skip-lint]
2022-12-27 03:42:36 +03:00

181 lines
7.8 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: 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> функция вернёт
существующее подключение. Чтобы принудительно создать новое соединение,
необходимо передать строку подключения функции <constant>PGSQL_CONNECT_FORCE_NEW</constant> в качестве
параметра <parameter>flags</parameter>.
</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
$dbconn = pg_connect("dbname=mary");
//подключиться к базе "mary"
$dbconn2 = pg_connect("host=localhost port=5432 dbname=mary");
//подключиться к базе "mary" на хосте "localhost", порт "5432"
$dbconn3 = pg_connect("host=sheep port=5432 dbname=mary user=lamb password=foo");
//подключиться к базе "mary" на хосте "sheep", используя имя пользователя и пароль
$conn_string = "host=sheep port=5432 dbname=test user=lamb password=bar";
$dbconn4 = pg_connect($conn_string);
//подключиться к базе "test" на хосте "sheep", используя имя пользователя и пароль
$dbconn5 = pg_connect("host=localhost options='--client_encoding=UTF8'");
//подключиться к базе на хосте "localhost" и передать параметр командной строки, задающий кодировку UTF-8
?>
]]>
</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
-->