mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 07:02:08 +01:00
- 参照下さい - 参照して下さい - 参照してください を「参照ください」に置き換えた。 個人的には「参照ください」は違和感のある日本語だが、既存の訳で圧倒的な優勢だったそれを採用した。 closes: #23
262 lines
9.7 KiB
XML
262 lines
9.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: b0a34b2fce160f558e3c81bf73121d16c9d56eb8 Maintainer: mumumu Status: ready -->
|
|
|
|
<refentry xml:id="function.mysql-xdevapi-getsession" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>getSession</refname>
|
|
<refpurpose>MySQL サーバーに接続する</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>mysql_xdevapi\Session</type><methodname>mysql_xdevapi\getSession</methodname>
|
|
<methodparam><type>string</type><parameter>uri</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
MySQL サーバーに接続します。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>uri</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<literal>mysqlx://user:password@host</literal> のような、MySQL サーバーへのURI。
|
|
</para>
|
|
<para>
|
|
URI のフォーマットは下記のとおりです:
|
|
</para>
|
|
<para>
|
|
<code>scheme://[user[:[password]]@]target[:port][?attribute1=value1&attribute2=value2...</code>
|
|
</para>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<para><literal>scheme</literal> は必須です。接続プロトコルです</para>
|
|
<para>mysql_xdevapi では、常に 'mysqlx' です(X プロトコル)</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para><literal>user</literal>: オプションです。認証される MySQL アカウント</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para><literal>password</literal>: オプションです。認証に使う MySQL ユーザのパスワード</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para><literal>target</literal>: 必須です。
|
|
接続が参照する サーバーインスタンスです:</para>
|
|
<para>* TCP接続 (ホスト名, IPv4 アドレス, または IPv6 アドレス)</para>
|
|
<para>* Unix ソケットのパス (ローカルファイルのパス)</para>
|
|
<para>* Windows 名前付きパイプ (ローカルファイルのパス)</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para><literal>port</literal>: オプションです。MySQL サーバーのネットワーク ポート</para>
|
|
<para>X プロトコルのデフォルトのポートは 33060 です</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
<literal>?attribute=value</literal>: この要素はオプションで、異なるオプションを含む
|
|
次のような辞書データを指定します:
|
|
</para>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<para>
|
|
<literal>auth</literal> (認証メカニズム) 属性は、接続の暗号化に関連があります。
|
|
追加の情報については、
|
|
<link xlink:href="&url.mysql.docs.connect.encryption;">Command
|
|
Options for Encrypted Connections</link> を参照ください。
|
|
|
|
'auth' 属性については、次の値がサポートされています: <literal>plain</literal>,
|
|
<literal>mysql41</literal>, <literal>external</literal>, <literal>sha256_mem</literal>.
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
<literal>connect-timeout</literal> 属性は、接続時と接続後の操作に影響します。
|
|
単一、複数のホストへの接続かに関わらず、接続単位で設定します。
|
|
</para>
|
|
<para>
|
|
接続タイムアウトは秒単位で正の整数を渡します。
|
|
0 を渡すと、タイムアウトを無効(つまり無限) にします。
|
|
connect-timeout を定義しないと、デフォルト値10を使います。
|
|
</para>
|
|
<para>
|
|
関連事項として、
|
|
MYSQLX_CONNECTION_TIMEOUT (秒単位のタイムアウト)
|
|
および、
|
|
MYSQLX_TEST_CONNECTION_TIMEOUT (テスト時に使います)
|
|
環境変数を、URI に connect-timeout を設定する代わりに設定し、使うことができます。
|
|
connect-timeout URI オプションは、これらの環境変数に優先します。
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
オプションの <literal>compression</literal> は、以下の値を受け付けます:
|
|
<literal>preferred</literal> (クライアントとサーバーが、お互いがサポートしているアルゴリズムを見つけるために交渉します。つまり、サポートされたアルゴリズムが見つからない場合は圧縮されません),
|
|
<literal>required</literal> ("preferred" と似ていますが、お互いがサポートしているアルゴリズムが見つからない場合は接続を終了します), または
|
|
<literal>disabled</literal> (この接続では圧縮が行われません)。 デフォルトは <literal>preferred</literal> です。
|
|
</para>
|
|
<para>
|
|
このオプションは 8.0.20 で追加されました。
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
オプションの <literal>compression-algorithms</literal> 属性は、
|
|
好みの圧縮アルゴリズム(および好みの優先順) を定義します:
|
|
<literal>zstd_stream</literal> (エイリアス: zstd),
|
|
<literal>lz4_message</literal> (エイリアス: lz4),
|
|
<literal>deflate_stream</literal> (エイリアス: deflate, zlib) が指定できます。
|
|
デフォルトでは、(システムで利用可能かどうかに依存しますが)
|
|
lz4_message, zstd_stream, deflate_stream の順番が使われます。
|
|
たとえば、compression-algorithms=[lz4,zstd_stream] という値を渡した場合、
|
|
lz4 が利用可能であれば lz4 を使いますが、そうでない場合は、zstd_stream が使われます。
|
|
lz4, zstd_stream 双方が利用できない場合、振る舞いは compression の値に依存します。
|
|
たとえば、compression=required の場合、エラーが出て接続は失敗します。
|
|
</para>
|
|
<para>
|
|
このオプションは 8.0.22 で追加されました。
|
|
</para>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</listitem>
|
|
</itemizedlist>
|
|
|
|
<example>
|
|
<title>URI の例</title>
|
|
<programlisting role="php">
|
|
mysqlx://foobar
|
|
mysqlx://root@localhost?socket=%2Ftmp%2Fmysqld.sock%2F
|
|
mysqlx://foo:bar@localhost:33060
|
|
mysqlx://foo:bar@localhost:33160?ssl-mode=disabled
|
|
mysqlx://foo:bar@localhost:33260?ssl-mode=required
|
|
mysqlx://foo:bar@localhost:33360?ssl-mode=required&auth=mysql41
|
|
mysqlx://foo:bar@(/path/to/socket)
|
|
mysqlx://foo:bar@(/path/to/socket)?auth=sha256_mem
|
|
mysqlx://foo:bar@[localhost:33060, 127.0.0.1:33061]
|
|
mysqlx://foobar?ssl-ca=(/path/to/ca.pem)&ssl-crl=(/path/to/crl.pem)
|
|
mysqlx://foo:bar@[localhost:33060, 127.0.0.1:33061]?ssl-mode=disabled
|
|
mysqlx://foo:bar@localhost:33160/?connect-timeout=0
|
|
mysqlx://foo:bar@localhost:33160/?connect-timeout=10&compression=required
|
|
mysqlx://foo:bar@localhost:33160/?connect-timeout=10&compression=required&compression-algorithms=[lz4,zstd_stream]
|
|
</programlisting>
|
|
</example>
|
|
|
|
<para>
|
|
関連する情報については、MySQL Shell の
|
|
<link xlink:href="&url.mysql.docs.connect.shell.uri;">Connecting using a URI String</link> を参照ください
|
|
</para>
|
|
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
<classname>Session</classname> オブジェクト
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
接続に失敗した場合は、<classname>Exception</classname> がスローされます。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title><function>mysql_xdevapi\getSession</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
try {
|
|
$session = mysql_xdevapi\getSession("mysqlx://user:password@host");
|
|
} catch(Exception $e) {
|
|
die("Connection could not be established: " . $e->getMessage());
|
|
}
|
|
|
|
$schemas = $session->getSchemas();
|
|
print_r($schemas);
|
|
|
|
$mysql_version = $session->getServerVersion();
|
|
print_r($mysql_version);
|
|
|
|
var_dump($collection->find("name = 'Alfred'")->execute()->fetchOne());
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => mysql_xdevapi\Schema Object
|
|
(
|
|
[name] => helloworld
|
|
)
|
|
[1] => mysql_xdevapi\Schema Object
|
|
(
|
|
[name] => information_schema
|
|
)
|
|
[2] => mysql_xdevapi\Schema Object
|
|
(
|
|
[name] => mysql
|
|
)
|
|
[3] => mysql_xdevapi\Schema Object
|
|
(
|
|
[name] => performance_schema
|
|
)
|
|
[4] => mysql_xdevapi\Schema Object
|
|
(
|
|
[name] => sys
|
|
)
|
|
)
|
|
|
|
80012
|
|
|
|
array(4) {
|
|
["_id"]=>
|
|
string(28) "00005ad66abf0001000400000003"
|
|
["age"]=>
|
|
int(42)
|
|
["job"]=>
|
|
string(7) "Butler"
|
|
["name"]=>
|
|
string(4) "Alfred"
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</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
|
|
-->
|