📜 ⬆️ ⬇️

Memcached - cache strategy

I want to greet the habrosocommunity. From pleasant impressions when registering at Habré - this is the atmosphere of fabulousness, which only happens in good old fairy tales from the Soviet Film.
So, the tears of emotion are gone, proceed. Below is the topic that led to the invite to Habr.

Memcached is used to cache data. This is done in order to avoid unnecessary database calls, i.e. in memcached save query results. This speeds up the work of the site and reduces the time of issuance of pages.
Kesh besides the advantages has its drawbacks. One of the cache problems is its relevance. In the “read only” mode of operation there are no difficulties. If we are dealing with data that changes, or changes often, the efficiency of caching drops sharply. The more often the data changes, the less efficient the cache. Usually, the cache is reset after the first change. And there is a reset at once all cached data. After a reset, requests go to the database and a new cache is filled. If there is one more change, the cache is reset again. Often it turns out that such a good thing as memcached does not bring any benefit to the server's performance, and also entails additional costs for memory, processor time.
One of the methods for solving this problem is a logical division of the cache into independent parts. If a cache reset occurs, then only for the part that has changed.

Consider one of these approaches in a bunch of Memcached - DB
')
If we make a logical separation on requests, then the question arises of how and what to divide, how often to update. Here it is necessary to give hints for each request, since the purpose of requests is different and it is not clear which requests to update and under what events. It requires a lot of effort to implement - and I, as a lazy programmer, are not interested.

Let's separate all references to the database by tables.

Suppose we have a query with reference to several tables. We take a query, analyze which tables in it, see if the data in the table has changed. If the data has changed, then the cache for the request is also updated. It sounds a bit complicated, the questions arise - how to do it all, but ultimately the implementation is quite simple.

Let's start the sketches:

* Each table we have will have a counter that changes every time the data in the table changes.
* When we perform the deletion and insertion of rows, when the records change - we increase these counters.
* Before executing a query, a list of affected tables is taken from it. On these tables we find the values ​​of the counter. We form these values ​​in one line and add as a comment to the request.

That's all the difficulties with this approach. To move to a new caching policy, we just need to make small changes to the code. An example demonstrating this approach is provided below. This example is completely independent and can be executed if you have PHP with support for the mysql and memcache extensions.
This approach increases the efficiency of data caching. When you flush the cache, only the data that belongs to the changed tables is deleted. To be more specific, the words “flush the cache” lose their meaning, the changed data becomes inaccessible and the cache continues to be filled with new keys for the same requests. If you have a “nasty” table, because of which the entire cache is often reset, then now such a table will not spoil the whole picture for you.

The method is viable, it was tested on one of the sites ( http://www.skachatreferat.ru ). Experience has shown that you should not neglect other methods of caching. That for data whose relevance is not critical at a refresh rate of every 5 minutes, it is better to use the simplest caching with setting the cache lifetime for a given period, in this case it is 5 minutes.

Take habrahabr, which provides access to articles. Here each article is a text field and a set of some attributes. Text changes rarely, while article attributes change frequently. For this reason, it makes sense to put only the text of the article in the cache, and to choose the attributes independently from the tables. As a result, the speed of access to data increases by an order of magnitude.

The fewer columns we choose, the better for performance. MySQL works with columns with data of a simple type an order of magnitude faster than with columns of type TEXT (where the text of the article is stored here). Through the use of these features achieved a significant performance gain.

Below is a script to demonstrate the method of dividing the cache into tables, the source code of which was promised to you. The script is completely independent and does not require any additional modules. Do not forget to specify the data for mysql and memcache at the beginning of the script:
  1. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  2. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  3. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  4. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  5. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  6. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  7. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  8. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  9. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  10. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  11. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  12. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  13. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  14. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  15. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  16. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  17. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  18. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  19. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  20. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  21. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  22. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  23. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  24. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  25. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  26. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  27. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  28. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  29. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  30. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  31. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  32. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  33. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  34. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  35. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  36. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  37. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  38. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  39. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  40. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  41. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  42. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  43. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  44. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  45. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  46. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  47. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  48. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  49. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  50. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  51. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  52. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  53. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  54. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  55. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  56. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  57. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  58. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  59. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  60. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  61. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  62. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  63. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  64. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  65. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  66. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  67. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  68. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  69. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  70. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  71. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  72. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  73. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  74. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  75. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  76. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  77. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  78. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  79. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  80. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  81. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  82. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  83. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  84. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  85. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  86. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  87. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  88. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  89. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  90. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  91. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  92. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  93. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  94. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  95. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  96. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>
  97. <? header ( 'Content-type: text/html; charset=UTF-8' ) ; $mysql_host = 'localhost' ; $mysql_username = 'root' ; $mysql_password = '12345' ; $mysql_database = 'test' ; // , $mysql_table1 = 'table1' ; $mysql_table2 = 'table2' ; $memcache_host = 'localhost' ; $memcache_port = 11211 ; $mysql = mysql_connect ( $mysql_host , $mysql_username , $mysql_password ) ; if ( ! $mysql ) die ( " MySQL: $mysql_username @ $mysql_host / $mysql_password " ) ; if ( ! mysql_select_db ( $mysql_database ) ) die ( " : $mysql_database " ) ; $memcache = new Memcache ; if ( ! $memcache -> pconnect ( $memcache_host , $memcache_port ) ) die ( "Memcached : $memcache_host : $memcache_port " ) ; function cacheGet ( $key ) { global $memcache ; return $memcache -> get ( $key ) ; } function cacheSet ( $key , $data , $delay ) { global $memcache ; return $memcache -> set ( $key , $data , 0 , $delay ) ; } function sqlExtractTables ( & $query ) { preg_match_all ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , $query , $tables ) ; if ( ! $tables [ 1 ] ) die ( " , '<<table_name>>': $query " ) ; $query = preg_replace ( "/\\<\\<([A-Za-z0-9\\_]+)\\>\\>/" , "\ \1 " , $query ) ; return $tables [ 1 ] ; } function sqlQuery ( $query ) { $resource = mysql_query ( $query ) ; if ( ! $resource ) die ( " : $query <br> " . mysql_error ( ) ) ; echo "<b> :</b> $query <br>" ; return $resource ; } function sqlSet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) cacheSet ( $table , uniqid ( time ( ) , true ) , 24 * 3600 ) ; return sqlQuery ( $query ) ; } function sqlGet ( $query ) { $tables = sqlExtractTables ( $query ) ; foreach ( $tables as $table ) $appendix .= cacheGet ( $table ) ; $appendix = "/*" . md5 ( $appendix ) . "*/" ; $query = $query . $appendix ; $cache_key = md5 ( $query ) ; $result = cacheGet ( $cache_key ) ; if ( $result !== false ) { echo "<b> :</b> $query <br>" ; return $result ; } else echo "<b> :</b> $query <br>" ; $resource = sqlQuery ( $query ) ; $result = array ( ) ; while ( $row = mysql_fetch_assoc ( $resource ) ) { $result [ ] = $row ; } cacheSet ( $cache_key , $result , 3600 ) ; return $result ; } ?> <h2>. </h2> <h3> 2 </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; // "select * from <<$mysql_table1>> where id=1", ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3> </h3> <? sqlSet ( "delete from << $mysql_table2 >> where 1=0" ) ; ?> <h3> </h3> <? sqlGet ( "select * from << $mysql_table1 >> limit 1" ) ; ?> <br> <? sqlGet ( "select * from << $mysql_table2 >> limit 1" ) ; ?> <h3>: , . </h3>



the source is here: www.skachatreferat.ru/demo.txt

Source: https://habr.com/ru/post/61736/


All Articles