php memcache new Memcache memcache- connect 127 11211 or die Could not

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
include('includes/connect.php');
// create key, and check cach
$key = md5("SELECT * FROM memcached_test where name='ashley'");
$get_result = $memcache>get($key);
if ($get_result) {
echo $get_result['name'];
echo $get_result['username'];
echo "Data Pulled From Cache";
}
else {
// get data from database and create cache
$query="SELECT * FROM memcached_test where name='ashley';";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
print_r($row);
$memcache>set($key, $row, TRUE, 20); // Store result 20 second
echo "Data Pulled from the Database";
}