getSessionConnect to a MySQL server
&reftitle.description;
mysql_xdevapi\Sessionmysql_xdevapi\getSessionstringuri
Connects to the MySQL server.
&reftitle.parameters;
uri
The URI to the MySQL server, such as mysqlx://user:password@host.
URI format:
scheme://[user[:[password]]@]target[:port][?attribute1=value1&attribute2=value2...scheme: required, the connection protocolIn mysql_xdevapi it is always 'mysqlx' (for X Protocol)user: optional, the MySQL user account for authenticationpassword: optional, the MySQL user's password for authenticationtarget: required, the server instance the connection refers to:* TCP connection (host name, IPv4 address, or IPv6 address)* Unix socket path (local file path)* Windows named-pipe (local file path)port: optional, network port of MySQL server.by default port for X Protocol is 33060?attribute=value: this element is optional and specifies a data dictionary that contains options,
e.g. for encrypted connections or 'auth'. For additional information, see
Command Options for Encrypted Connections.
The following values for 'auth' attribute are supported (authentication mechanism):
plainmysql41externalsha256_memURI examples
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
For related information, see MySQL Shell's
Connecting using a URI String.
&reftitle.returnvalues;
A mysql_xdevap\Session object.
&reftitle.examples;
mysql_xdevapi\getSession example
getSchemas();
print_r($schemas);
$mysql_version = $session->getServerVersion();
print_r($mysql_version);
var_dump($collection->find("name = 'Alfred'")->execute()->fetchOne());
?>
]]>
&example.outputs.similar;
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"
}
]]>