<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<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>Connect to a MySQL server</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>
   Connects to the MySQL server.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <variablelist>
   <varlistentry>
    <term><parameter>uri</parameter></term>
    <listitem>
     <para>
      The URI to the MySQL server, such as <literal>mysqlx://user:password@host</literal>.
     </para>
     <para>
      URI format:
     </para>
     <para>
      <code>scheme://[user[:[password]]@]target[:port][?attribute1=value1&amp;attribute2=value2...</code>
     </para>
     <itemizedlist>
      <listitem>
        <para><literal>scheme</literal>: required, the connection protocol</para>
        <para>In mysql_xdevapi it is always 'mysqlx' (for X Protocol)</para>
      </listitem>
      <listitem>
        <para><literal>user</literal>: optional, the MySQL user account for authentication</para>
      </listitem>
      <listitem>
        <para><literal>password</literal>: optional, the MySQL user's password for authentication</para>
      </listitem>
      <listitem>
        <para><literal>target</literal>: required, the server instance the connection refers to:</para>
        <para>* TCP connection (host name, IPv4 address, or IPv6 address)</para>
        <para>* Unix socket path (local file path)</para>
        <para>* Windows named-pipe (local file path)</para>
      </listitem>
      <listitem>
        <para><literal>port</literal>: optional, network port of MySQL server.</para>
        <para>by default port for X Protocol is 33060</para>
      </listitem>
      <listitem>
        <para>
          <literal>?attribute=value</literal>: this element is optional and specifies a data dictionary that contains options, 
          e.g. for encrypted connections or 'auth'. For additional information, see
          <link xlink:href="&url.mysql.docs.connect.encryption;">Command Options for Encrypted Connections</link>.
        </para>
        <para>
          
        </para>
        <para>
          The following values for 'auth' attribute are supported (authentication mechanism):
        </para>
        <itemizedlist>
          <listitem><para>plain</para></listitem>
          <listitem><para>mysql41</para></listitem>
          <listitem><para>external</para></listitem>
          <listitem><para>sha256_mem</para></listitem>
         </itemizedlist>
       </listitem>
      </itemizedlist>

  <example>
  <title>URI examples</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&amp;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)&amp;ssl-crl=(/path/to/crl.pem)
mysqlx://foo:bar@[localhost:33060, 127.0.0.1:33061]?ssl-mode=disabled
  </programlisting>
</example>

   <para>
    For related information, see MySQL Shell's
    <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>
   A <classname>mysql_xdevap\Session</classname> object.
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <example>
   <title><function>mysql_xdevapi\getSession</function> example</title>
   <programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@host");
if ($session === NULL) {
    die("Connection could not be established");
}

$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
-->