| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\MysqlndMsException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Returns a list of currently configured servers. |
| 9 |
* |
| 10 |
* @param mixed $connection A MySQL connection handle obtained from any of the |
| 11 |
* connect functions of the mysqli, |
| 12 |
* mysql or |
| 13 |
* PDO_MYSQL extensions. |
| 14 |
* @return array FALSE on error. Otherwise, returns an array with two entries |
| 15 |
* masters and slaves each of which contains |
| 16 |
* an array listing all corresponding servers. |
| 17 |
* |
| 18 |
* The function can be used to check and debug the list of servers currently |
| 19 |
* used by the plugin. It is mostly useful when the list of servers changes at |
| 20 |
* runtime, for example, when using MySQL Fabric. |
| 21 |
* |
| 22 |
* masters and slaves server entries |
| 23 |
* @throws MysqlndMsException |
| 24 |
* |
| 25 |
*/ |
| 26 |
function mysqlnd_ms_dump_servers($connection): array |
| 27 |
{ |
| 28 |
error_clear_last(); |
| 29 |
$result = \mysqlnd_ms_dump_servers($connection); |
| 30 |
if ($result === false) { |
| 31 |
throw MysqlndMsException::createFromPhpError(); |
| 32 |
} |
| 33 |
return $result; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
/** |
| 38 |
* MySQL Fabric related. |
| 39 |
* |
| 40 |
* Switch the connection to the nodes handling global sharding queries |
| 41 |
* for the given table name. |
| 42 |
* |
| 43 |
* @param mixed $connection A MySQL connection handle obtained from any of the |
| 44 |
* connect functions of the mysqli, |
| 45 |
* mysql or |
| 46 |
* PDO_MYSQL extensions. |
| 47 |
* @param mixed $table_name The table name to ask Fabric about. |
| 48 |
* @return array FALSE on error. Otherwise, TRUE |
| 49 |
* @throws MysqlndMsException |
| 50 |
* |
| 51 |
*/ |
| 52 |
function mysqlnd_ms_fabric_select_global($connection, $table_name): array |
| 53 |
{ |
| 54 |
error_clear_last(); |
| 55 |
$result = \mysqlnd_ms_fabric_select_global($connection, $table_name); |
| 56 |
if ($result === false) { |
| 57 |
throw MysqlndMsException::createFromPhpError(); |
| 58 |
} |
| 59 |
return $result; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
/** |
| 64 |
* MySQL Fabric related. |
| 65 |
* |
| 66 |
* Switch the connection to the shards responsible for the |
| 67 |
* given table name and shard key. |
| 68 |
* |
| 69 |
* @param mixed $connection A MySQL connection handle obtained from any of the |
| 70 |
* connect functions of the mysqli, |
| 71 |
* mysql or |
| 72 |
* PDO_MYSQL extensions. |
| 73 |
* @param mixed $table_name The table name to ask Fabric about. |
| 74 |
* @param mixed $shard_key The shard key to ask Fabric about. |
| 75 |
* @return array FALSE on error. Otherwise, TRUE |
| 76 |
* @throws MysqlndMsException |
| 77 |
* |
| 78 |
*/ |
| 79 |
function mysqlnd_ms_fabric_select_shard($connection, $table_name, $shard_key): array |
| 80 |
{ |
| 81 |
error_clear_last(); |
| 82 |
$result = \mysqlnd_ms_fabric_select_shard($connection, $table_name, $shard_key); |
| 83 |
if ($result === false) { |
| 84 |
throw MysqlndMsException::createFromPhpError(); |
| 85 |
} |
| 86 |
return $result; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
/** |
| 91 |
* Returns an array which describes the last used connection from the plugins |
| 92 |
* connection pool currently pointed to by the user connection handle. If using the |
| 93 |
* plugin, a user connection handle represents a pool of database connections. |
| 94 |
* It is not possible to tell from the user connection handles properties to which |
| 95 |
* database server from the pool the user connection handle points. |
| 96 |
* |
| 97 |
* The function can be used to debug or monitor PECL mysqlnd_ms. |
| 98 |
* |
| 99 |
* @param mixed $connection A MySQL connection handle obtained from any of the |
| 100 |
* connect functions of the mysqli, |
| 101 |
* mysql or |
| 102 |
* PDO_MYSQL extensions. |
| 103 |
* @return array FALSE on error. Otherwise, an |
| 104 |
* array which describes the connection used to |
| 105 |
* execute the last statement on. |
| 106 |
* |
| 107 |
* Array which describes the connection. |
| 108 |
* @throws MysqlndMsException |
| 109 |
* |
| 110 |
*/ |
| 111 |
function mysqlnd_ms_get_last_used_connection($connection): array |
| 112 |
{ |
| 113 |
error_clear_last(); |
| 114 |
$result = \mysqlnd_ms_get_last_used_connection($connection); |
| 115 |
if ($result === false) { |
| 116 |
throw MysqlndMsException::createFromPhpError(); |
| 117 |
} |
| 118 |
return $result; |
| 119 |
} |
| 120 |
|