-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbibdb.php
67 lines (57 loc) · 1.95 KB
/
bibdb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* SQL queries.
*
* @package ExternBib
* @author Michael Kuron
* @copyright 2016 The Authors
* @license https://opensource.org/licenses/BSD-3-Clause New BSD License
* @link https://github.com/olenz/externbib
*/
// alternative sqlite functions for the dba_* functions
function bibdb_open($path, $mode, $table="default_table", $error_log="/var/log/mediawiki/error.log")
{
try {
$sqliteobject = new SQLite3($path);
} catch (Exception $e) {
error_log("Error in bibdb_open: $e->getMessage()\n", 3, $error_log);
return false;
}
try {
$sqliteobject->exec("CREATE TABLE IF NOT EXISTS $table (KEY TEXT, VALUE TEXT)");
} catch (Exception $e) {
error_log("Error in bibdb_open: $e->getMessage()\n", 3, $error_log);
return false;
}
return $sqliteobject;
}
function bibdb_insert($keydata, $valuedata, $sqliteobject, $table="default_table")
{
try {
$savevalue = SQLite3::escapeString($valuedata);
$sqlstring = "INSERT INTO $table (KEY, VALUE) VALUES (" . "'$keydata', " . "'$savevalue');";
$sqliteobject->exec($sqlstring);
} catch (Exception $e) {
return false;
}
}
function bibdb_query($sqliteobject, $table="default_table")
{
$query = "SELECT * FROM $table;";
$res = $sqliteobject->query($query);
return $res;
}
function bibdb_fetch($key, $sqliteobject, $table="default_table")
{
$sqlstring = "SELECT VALUE FROM $table WHERE KEY='$key';";
$fetch = $sqliteobject->querySingle($sqlstring);
$fetch_readable = print_r($fetch, true);
$sqliteobject_readable = print_r($sqliteobject, true);
return $fetch;
}
function bibdb_close($sqliteobject)
{
$status = $sqliteobject->close();
return $status;
}
?>