getSession
(No version information available, might only be in Git)
getSession — Connect to a MySQL server
Description
$uri
) : mysql_xdevapi\SessionConnects to the MySQL server.
Liste de paramètres
-
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 protocol
In mysql_xdevapi it is always 'mysqlx' (for X Protocol)
-
user: optional, the MySQL user account for authentication
-
password: optional, the MySQL user's password for authentication
-
target: 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 different options, including:
-
The auth (authentication mechanism) attribute as it relates to encrypted connections. For additional information, see » Command Options for Encrypted Connections. The following 'auth' values are supported: plain, mysql41, external, and sha256_mem.
-
The connect-timeout attribute affects the connection and not subsequent operations. It is set per connection whether on a single or multiple hosts.
Pass in a positive integer to define the connection timeout in seconds, or pass in 0 (zero) to disable the timeout (infinite). Not defining connect-timeout uses the default value of 10.
Related, the MYSQLX_CONNECTION_TIMEOUT (timeout in seconds) and MYSQLX_TEST_CONNECTION_TIMEOUT (used while running tests) environment variables can be set and used instead of connect-timeout in the URI. The connect-timeout URI option has precedence over these environment variables.
-
Exemple #1 URI 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
mysqlx://foo:bar@localhost:33160/?connect-timeout=0
mysqlx://foo:bar@localhost:33160/?connect-timeout=10For related information, see MySQL Shell's » Connecting using a URI String.
-
Exemples
Exemple #2 mysql_xdevapi\getSession() example
<?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());
?>
L'exemple ci-dessus va afficher quelque chose de similaire à :
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" }
Document créé le 30/01/2003, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/php-rf-function.mysql-xdevapi-getsession.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.