prepare('SELECT cvalue FROM functional_cache WHERE ckey = ?'); $stmt->execute(array($key)); if($row = $stmt->fetch()) { return $row[0]; } else { return null; } } function put($con, $key, $value) { $stmt = $con->prepare('MERGE INTO functional_cache(ckey,cvalue) VALUES(?,?)'); $stmt->execute(array($key, $value)); } function remove($con, $key) { $stmt = $con->prepare('DELETE FROM functional_cache WHERE ckey = ?'); $stmt->execute(array($key)); } function listall($con, $f) { $stmt = $con->prepare('SELECT ckey,cvalue FROM functional_cache'); $stmt->execute(array()); while($row = $stmt->fetch()) { $f($row); } } function test($con) { // basic put, get and remove put($con, 'v', 123); echo get($con, 'v') . "\r\n"; remove($con, 'v'); echo get($con, 'v') . "\r\n"; put($con, 'v', 123); echo get($con, 'v') . "\r\n"; // persistence $counter = get($con, 'counter'); if($counter == null) { $counter = 0; } $counter++; echo $counter . "\r\n"; put($con, 'counter', $counter); // list all listall($con, function($row) { echo $row[0] . ' = ' . $row[1] . "\r\n"; }); // listener not supported } $con = new PDO('odbc:ARNEPC4_IGNITE'); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $con->query('CREATE TABLE IF NOT EXISTS functional_cache (ckey VARCHAR(16) NOT NULL, cvalue INTEGER NOT NULL, PRIMARY KEY(ckey))'); test($con); ?>