©
This document uses PHP Chinese website manual Release
After associating a MySQL connection with a Memcache connection using
mysqnd_memcache_set() the plugin attempts to transparently
replace SQL SELECT
statements by a memcache access. For that purpose the plugin monitors
all SQL statements executed and tries to match the statement string
against MYSQLND_MEMCACHE_DEFAULT_REGEXP
.
In case of a match, the mysqlnd memcache plugin checks whether the
SELECT is accessing only columns of a mapped table and
the WHERE clause is limited to a single key lookup.
In case of the example SQL table, the plugin will use the Memcache interface of the MySQL server to fetch results for a SQL query like SELECT f1, f2, f3 WHERE id = n.
Example #1 Basic example.
<?php
$mysqli = new mysqli ( "host" , "user" , "passwd" , "database" );
$memc = new Memcached ();
$memc -> addServer ( "host" , 11211 );
mysqlnd_memcache_set ( $mysqli , $memc );
$result = $mysqli -> query ( "SELECT f1, f2, f3 FROM test WHERE id = 1" );
while ( $row = $result -> fetch_row ()) {
print_r ( $row );
}
$mysqli -> query ( "SELECT id FROM test WHERE f1 = 'Lady'" );
while ( $row = $result -> fetch_row ()) {
print_r ( $row );
}
?>
以上例程会输出:
array( [f1] => Hello [f2] => World [f3] => ! ) array( [id] => 2 )