All pastes #2117287 Raw Edit

defaultro

public text v1 · immutable
#2117287 ·published 2012-02-10 23:32 UTC
rendered paste body
<?php

$MEMCACHE_SERVERS = array(
    "127.0.0.1:11211", //web1
    "127.0.0.1:11212", //web2
    "127.0.0.1:11213"  //web3
);
$memcache = new Memcache();
foreach($MEMCACHE_SERVERS as $server){ 
    $memcache->addServer ( $server );
}
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect"); //connect to memcached server

$link = mysql_connect('localhost','root','secret');
if (!$link || !mysql_select_db('mysql',$link)) {
   return($link);
   die('Unable to connect.');
}
$sql = "INSERT INTO employee values ('john', 'malkovich')";
$querySuccess = mysql_query($sql);

if ($querySuccess === true) {
   // We build a unique key that we can build again later
   // We will use the word 'product' plus our product's id (eg. "product_12")
   $key = 'employee_data' ;

   // We store an associative array containing our product data
   $product = array('name' => 'john', 'lastname' => 'malkovich');

   // And we ask Memcached to store that data
   $memcache->set($key, $product);
   echo "Successfully inserted data to Memcache server";
}
?>