Upgrade to sqlite3
This commit is contained in:
parent
5098db94eb
commit
95d8ede9ac
|
@ -1,4 +1,6 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<?php
|
||||
require_once("config.php");
|
||||
?><html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Pamela</title>
|
||||
<script src="js/jquery-1.3.2.js" type="text/javascript"></script>
|
||||
|
|
|
@ -4,7 +4,7 @@ require_once("config.php");
|
|||
function get_db() {
|
||||
static $db = NULL;
|
||||
if ($db == NULL) {
|
||||
$db = sqlite_open(SQLITE_DB);
|
||||
$db = new SQLite3(SQLITE_DB);
|
||||
}
|
||||
return $db;
|
||||
}
|
||||
|
|
11
lib/macs.php
11
lib/macs.php
|
@ -4,10 +4,9 @@ require_once("lib/db.php");
|
|||
function macs_get() {
|
||||
$results = array();
|
||||
$db = get_db();
|
||||
$q = sqlite_query($db, "select mac from macs where committime > strftime('%s','now') - ".MACFILE_TTL);
|
||||
$q = $db->query("select mac from macs where committime > strftime('%s','now') - ".MACFILE_TTL);
|
||||
if (!$q) return $results;
|
||||
while(sqlite_has_more($q)) {
|
||||
$row = sqlite_fetch_array($q, SQLITE_ASSOC);
|
||||
while($row = $q->fetch_array(SQLITE_ASSOC)) {
|
||||
$results[] = $row['mac'];
|
||||
}
|
||||
return $results;
|
||||
|
@ -15,11 +14,11 @@ function macs_get() {
|
|||
|
||||
function macs_add($mac) {
|
||||
$db = get_db();
|
||||
$mac = sqlite_escape_string($mac);
|
||||
return sqlite_exec($db, "insert or replace into macs values (\"$mac\", strftime('%s','now'))");
|
||||
$mac = $db->escape_string($mac);
|
||||
return $db->exec("insert or replace into macs values (\"$mac\", strftime('%s','now'))");
|
||||
}
|
||||
|
||||
function macs_purge() {
|
||||
$db = get_db();
|
||||
return sqlite_exec($db, "delete from macs where committime <= strftime('%s','now') - ".MACFILE_TTL);
|
||||
return $db->exec("delete from macs where committime <= strftime('%s','now') - ".MACFILE_TTL);
|
||||
}
|
||||
|
|
|
@ -4,10 +4,9 @@ require_once("lib/db.php");
|
|||
function known_macs_get() {
|
||||
$results = array();
|
||||
$db = get_db();
|
||||
$q = sqlite_query($db, "select * from knownmacs");
|
||||
$q = $db->query("select * from knownmacs");
|
||||
if (!$q) return $results;
|
||||
while(sqlite_has_more($q)) {
|
||||
$row = sqlite_fetch_array($q, SQLITE_ASSOC);
|
||||
while($row = $q->fetch_array(SQLITE_ASSOC)) {
|
||||
$results[$row['mac']] = $row['name'];
|
||||
}
|
||||
return $results;
|
||||
|
@ -16,10 +15,9 @@ function known_macs_get() {
|
|||
function known_macs_get_by_user($userid) {
|
||||
$results = array();
|
||||
$db = get_db();
|
||||
$q = sqlite_query($db, "select * from knownmacs where userid = \"userid\"");
|
||||
$q = $db->query("select * from knownmacs where userid = \"userid\"");
|
||||
if (!$q) return $results;
|
||||
while(sqlite_has_more($q)) {
|
||||
$row = sqlite_fetch_array($q, SQLITE_ASSOC);
|
||||
while($row = $q->fetch_array(SQLITE_ASSOC)) {
|
||||
$results[$row['mac']] = $row['name'];
|
||||
}
|
||||
return $results;
|
||||
|
@ -27,10 +25,10 @@ function known_macs_get_by_user($userid) {
|
|||
|
||||
function known_macs_upsert($mac, $name, $show) {
|
||||
$db = get_db();
|
||||
$mac = sqlite_escape_string($mac);
|
||||
$name = sqlite_escape_string($name);
|
||||
$show = sqlite_escape_string($show);
|
||||
return sqlite_exec($db, "insert into knownmacs or replace (mac, name, show) values (\"$mac\", \"$name\", \"$show\")");
|
||||
$mac = $db->escape_string($mac);
|
||||
$name = $db->escape_string($name);
|
||||
$show = $db->escape_string($show);
|
||||
return $db->exec("insert into knownmacs or replace (mac, name, show) values (\"$mac\", \"$name\", \"$show\")");
|
||||
}
|
||||
|
||||
function known_macs_translate($macs) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user