以下の定数が定義されています。 この関数の拡張モジュールが PHP 組み込みでコンパイルされているか、 実行時に動的にロードされている場合のみ使用可能です。
SQL hint related
The mysqlnd replication and load balancing plugin (mysqlnd_ms) does read/write splitting to direct write queries to a MySQL master server and read-only queries to MySQL slave servers in a MySQL replication setup. The plugin has a built-in read/write split logic. The logic is very basic. All queries which start with SELECT are considered read-only queries which shall be send to a MySQL slave server listed in the plugin configuration file. All other queries shall be directed to the MySQL master server specified in the plugin configuration file.
User supplied SQL hints can be used to overrule automatic read/write splitting to gain full control on the process. SQL hints are standards compliant SQL comments. The plugin will scan the beginning of a query string for a SQL comment with certain contents which control query redirection. Other systems involved in the query processing are unaffected by the plugins SQL hints because other systems will ignore the SQL comments.
The plugin supports three SQL hints to direct queries to the MySQL slave servers, the MySQL master server and the last used MySQL server. SQL hints must be placed at the beginning to be recognized by the plugin.
It is recommended to use the string constants MYSQLND_MS_MASTER_SWITCH, MYSQLND_MS_SLAVE_SWITCH and MYSQLND_MS_LAST_USED_SWITCH instead of their literal values for better portability.
<?php
/* Use constants for maximum portability */
$master_query = "/*" . MYSQLND_MS_MASTER_SWITCH . "*/SELECT id FROM test";
/* Valid but less portable: using literal instad of constant */
$slave_query = "/*ms=slave*/SHOW TABLES";
printf("master_query = '%s'\n", $master_query);
printf("slave_query = '%s'\n", $slave_query);
?>
上の例の出力は以下となります。
master_query = /*ms=master*/SELECT id FROM test slave_query = /*ms=slave*/SHOW TABLES
mysqlnd_ms_is_select() related
Other
The plugins version number can be obtained using MYSQLND_MS_VERSION or MYSQLND_MS_VERSION_ID. MYSQLND_MS_VERSION is the string representation of the numerical version number MYSQLND_MS_VERSION_ID, which is an integer such as 10000. Developers can calculate the version number as follows.
Version (part) | Example |
---|---|
Major*10000 | 1*10000 = 10000 |
Minor*100 | 0*100 = 0 |
Patch | 0 = 0 |
MYSQLND_MS_VERSION_ID | 10000 |