Перечисленные ниже константы определены данным расширением и могут быть доступны только в том случае, если PHP был собран с поддержкой этого расширения или же в том случае, если данное расширение было подгружено во время выполнения.
SQL hint related
Пример #1 Using SQL hint constants
The query cache is controlled by SQL hints. SQL hints are used to enable and disable caching. SQL hints can be used to set the TTL of a query.
The SQL hints recognized by the query cache can be manually changed at compile time. This makes it possible to use mysqlnd_qc in environments in which the default SQL hints are already taken and interpreted by other systems. Therefore it is recommended to use the SQL hint string constants instead of manually adding the default SQL hints to the query string.
<?php
/* Use constants for maximum portability */
$query = "/*" . MYSQLND_QC_ENABLE_SWITCH . "*/SELECT id FROM test";
/* Valid but less portable: default TTL */
$query = "/*qc=on*/SELECT id FROM test";
/* Valid but less portable: per statement TTL */
$query = "/*qc=on*//*qc_ttl=5*/SELECT id FROM test";
printf("MYSQLND_QC_ENABLE_SWITCH: %s\n", MYSQLND_QC_ENABLE_SWITCH);
printf("MYSQLND_QC_DISABLE_SWITCH: %s\n", MYSQLND_QC_DISABLE_SWITCH);
printf("MYSQLND_QC_TTL_SWITCH: %s\n", MYSQLND_QC_TTL_SWITCH);
?>
Результат выполнения данных примеров:
MYSQLND_QC_ENABLE_SWITCH: qc=on MYSQLND_QC_DISABLE_SWITCH: qc=off MYSQLND_QC_TTL_SWITCH: qc_ttl=
MYSQLND_QC_ENABLE_SWITCH
(string)
MYSQLND_QC_DISABLE_SWITCH
(string)
MYSQLND_QC_TTL_SWITCH
(string)
MYSQLND_QC_SERVER_ID_SWITCH
(string)
mysqlnd_qc_set_cache_condition() related
Пример #2 Example mysqlnd_qc_set_cache_condition() usage
The function mysqlnd_qc_set_cache_condition() allows setting conditions for automatic caching of statements which don't begin with the SQL hints necessary to manually enable caching.
<?php
/* Cache all accesses to tables with the name "new%" in schema/database "db_example" for 1 second */
if (!mysqlnd_qc_set_cache_condition(MYSQLND_QC_CONDITION_META_SCHEMA_PATTERN, "db_example.new%", 1)) {
die("Failed to set cache condition!");
}
$mysqli = new mysqli("host", "user", "password", "db_example", "port");
/* cached although no SQL hint given */
$mysqli->query("SELECT id, title FROM news");
$pdo_mysql = new PDO("mysql:host=host;dbname=db_example;port=port", "user", "password");
/* not cached: no SQL hint, no pattern match */
$pdo_mysql->query("SELECT id, title FROM latest_news");
/* cached: TTL 1 second, pattern match */
$pdo_mysql->query("SELECT id, title FROM news");
?>
MYSQLND_QC_CONDITION_META_SCHEMA_PATTERN
(int)
Other
The plugin version number can be obtained using either
MYSQLND_QC_VERSION
, which is the string representation
of the numerical version number, or MYSQLND_QC_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_QC_VERSION_ID | 10000 |
MYSQLND_QC_VERSION
(string)
1.0.0-prototype.
MYSQLND_QC_VERSION_ID
(int)