Memcache Learning a complete example of PHP

Source: Internet
Author: User
Tags stmt

1 Header("Content-type:text/html;charset=utf-8");2 /*3 PHP set up distributed memcache access4 5 */6 //Create a Memcache object7 $mem=NewMemcache;8 9 //Connecting Memcache serversTen $memConnect (' localhost ', 11211); One $memAddserver (' 192.168.1.102 ', 11211);//add a server to the server A  -  - /*$mem, add (' One ', ' This is Memcache test ', memcache_compressed,1000); the $mem, add (' N ', Array (' 111 ', ' 222 ', ' 333 '), memcache_compressed,0); - $mem, add (' Three ', New Test (), memcache_compressed,0); - $mem, add (' Four ', 100,memcache_compressed,0);*/ -  + //Connection and operation of the database -  + $key= "MyData"; A //memcache data directly from memory at $data=$mem-A Get ($key); - //If the data is returned from the content, if the database is not connected, execute the SQL statement -  - if(Empty($data)){ -  -     $sql= "Select ' id ', ' title ', ' Author ', ' Content ', ' add_time ' from ' the ' News ' ORDER by ' id ' = 1"; in  -     Try{ to         $pdo=NewPDO ("Mysql:host=localhost;dbname=ci", ' root ', ' root '); +         //Var_dump ($pdo); -}Catch(pdoexception$e){ the         Echo"Database link failed!".$e->getmessage ($sql); *     } $ Panax Notoginseng     //get data, execute query statement -     $stmt=$pdo-Prepare ($sql); the  +     $stmt-execute (); A  the     $data=$stmt-Fetchall (PDO::FETCH_ASSOC); +  -     $mem-Add ($key,$data, memcache_compressed,10); $  $     Echo"This is the first time you've accessed data from a database and put it in memory!"; - } - Echo"<pre>"; the Print_r($data); - Echo"</pre>";Wuyi //Close Memcache Connection the $memClose ();

Memcache Learning a complete example of PHP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.