When I was in sae, the built-in mysql class was quite comfortable. Later, I encapsulated the SQL statement executed by the runSql method. The getData method obtained the result array and the Transactions method implemented the transaction. MysqlnewFaMysql ();} functionset ($ key, $ value, $ expire31536000) {the default validity period is one year $ nowti.
When I was in sae, the built-in mysql class was quite comfortable. Later, I encapsulated the SQL statement executed by the runSql method. The getData method obtained the result array and the Transactions method implemented the transaction. Mysql = new FaMysql ();} function set ($ key, $ value, $ expire = 31536000) {// The default validity period is one year. $ now = ti
When I was in sae, the built-in mysql class was quite comfortable. Later, I encapsulated the SQL statement executed by the runSql method. The getData method obtained the result array and the Transactions method implemented the transaction. Mysql = mysql_connect ($ options ['host'], $ options ['username'], $ options ['Password']) or die ("Database connection error. "); mysql_select_db ($ options ['database'], $ this-> mysql); mysql_query (" set names '". $ options ['charset']. "'");} public function Transactions (array $ SQL) {mysql_query ("BEGIN"); $ r = 1; foreach ($ SQL as $ key => $ row) {$ res = mysql_query ($ row); if (! $ Res) {$ r = 0 ;}} if (! $ R) {mysql_query ("ROLLBACK");} else {mysql_query ("COMMIT");} mysql_query ("END");} public function runSql ($ SQL) {mysql_query ($ SQL) or die (mysql_error ();} public function getData ($ SQL) {$ result = mysql_query ($ SQL) or die (mysql_error ()); $ array = array (); while ($ row = mysql_fetch_assoc ($ result) {$ array [] = $ row;} return $ array ;}} didn't buy vps at the beginning, the RP host does not provide memcache cache, so you can implement it yourself. The set Method stores data, the get method obtains data, and the del method deletes data. Only string is supported. Class FaMemcache {private $ mysql; private $ TABLENAME = 'memcache'; public function _ construct () {$ this-> mysql = new FaMysql ();} function set ($ key, $ value, $ expire = 31536000) {// The default validity period is one year $ now = time (); $ valid = $ now + $ expire; $ data = $ this-> mysql-> getData ("SELECT Fa_key FROM '$ this-> TABLENAME 'where Fa_key =' $ key '"); if (count ($ data )! = 0) {$ this-> mysql-> runsql ("updat' $ this-> TABLENAME 'set Fa_value = '$ value ', valid = '$ valid' WHERE Fa_key =' $ key '");} else {$ this-> mysql-> runsql ("insert into '$ this-> TABLENAME' (Fa_key, Fa_value, Valid) VALUES ('$ key',' $ value ', '$ valid') ") ;}} function get ($ key) {$ now = time (); $ data = $ this-> mysql-> getData ("SELECT Fa_value FROM '$ this-> TABLENAME 'where Fa_key =' $ key' AND $ now> Valid "); if (count ($ Data )! = 0) {return $ data [0] ['fa _ value'];} else {return null;} function del ($ key) {$ this-> mysql-> runsql ("delete from '$ this-> TABLENAME 'where Fa_key =' $ key '");}}
Original article address: mysql-based imitation memcache cache class. Thank you for sharing it with the original author.