48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
require_once('lassospkit_storage.inc.php');
|
|
|
|
class LassoSPKitMySqlStore implements LassoSPKitStore {
|
|
private $db;
|
|
private $table;
|
|
|
|
function __construct() {
|
|
$host = LassoSPKitConfig::get('mysql_host');
|
|
$user = LassoSPKitConfig::get('mysql_user');
|
|
$password = LassoSPKitConfig::get('mysql_password');
|
|
$database = LassoSPKitConfig::get('mysql_database');
|
|
$this->table = $table = LassoSPKitConfig::get('mysql_table');
|
|
$this->db = mysql_connect($host, $user, $password);
|
|
mysql_select_db($database);
|
|
mysql_query('CREATE TABLE IF NOT EXISTS ' . $table . '(nameid varchar(50), record varchar(2000), PRIMARY KEY (nameid))', $this->db);
|
|
}
|
|
function get($key) {
|
|
$result = mysql_query('SELECT record FROM ' . $this->table, $this->db);
|
|
if ($result) {
|
|
return @unserialize(mysql_result($result, 0));
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
function __destruct() {
|
|
mysql_close($this->db);
|
|
}
|
|
function set($key,$value) {
|
|
$sql = sprintf("REPLACE %s VALUES ('%s','%s')",
|
|
$this->table,
|
|
mysql_real_escape_string($key),
|
|
mysql_real_escape_string(serialize($record)));
|
|
$result = mysql_query($sql, $this->db);
|
|
}
|
|
function delete($key) {
|
|
$sql = sprintf("DELETE FROM %s WHERE nameid = '%s'",
|
|
$this->table,
|
|
mysql_real_escape_string($key));
|
|
mysql_query($sql, $this->db);
|
|
}
|
|
function alias($key,$alias) {
|
|
}
|
|
function linkcount($key) {
|
|
throw new Exception("Not implemented");
|
|
}
|
|
}
|