1 <!-- $Id: wiki_mysql.php3,v 1.5 2000-06-08 22:11:05 ahollosi Exp $ -->
9 RetrievePage($dbi, $pagename)
10 InsertPage($dbi, $pagename, $pagehash)
11 IsWikiPage($dbi, $pagename)
12 InitTitleSearch($dbi, $search)
13 TitleSearchNextMatch($dbi, &$pos)
14 InitFullSearch($dbi, $search)
15 FullSearchNextMatch($dbi, &$pos)
19 // open a database and return the handle
20 // ignores MAX_DBM_ATTEMPTS
22 function OpenDataBase($dbname) {
23 global $mysql_server, $mysql_user, $mysql_pwd, $mysql_db;
25 if (!($dbc = mysql_pconnect($mysql_server, $mysql_user, $mysql_pwd))) {
26 echo "Cannot establish connection to database, giving up.";
29 if (!mysql_select_db($mysql_db, $dbc)) {
30 echo "Cannot open database, giving up.";
35 $dbi['table'] = $dbname;
40 function CloseDataBase($dbi) {
42 // mysql connections are established as persistant
43 // they cannot be closed through mysql_close()
47 // Return hash of page + attributes or default
48 function RetrievePage($dbi, $pagename) {
49 $pagename = addslashes($pagename);
50 if ($res = mysql_query("select hash from $dbi[table] where page='$pagename'", $dbi['dbc'])) {
51 if ($o = mysql_fetch_object($res)) {
52 // unserialize data into a hash
53 $pagehash = unserialize($o->hash);
62 // Either insert or replace a key/value (a page)
63 function InsertPage($dbi, $pagename, $pagehash) {
64 $pagename = addslashes($pagename);
65 $pagedata = addslashes(serialize($pagehash));
67 if (!mysql_query("replace into $dbi[table] (page, hash) values ('$pagename', '$pagedata')", $dbi['dbc'])) {
68 echo "error writing value";
75 function IsWikiPage($dbi, $pagename) {
76 $pagename = addslashes($pagename);
77 if ($res = mysql_query("select count(*) from $dbi[table] where page='$pagename'", $dbi['dbc'])) {
78 return(mysql_result($res, 0));
83 // setup for title-search
84 function InitTitleSearch($dbi, $search) {
85 $search = addslashes($search);
86 $res = mysql_query("select page from $dbi[table] where page like '%$search%' order by page", $dbi["dbc"]);
92 // iterating through database
93 function TitleSearchNextMatch($dbi, $res) {
94 if($o = mysql_fetch_object($res)) {
103 // setup for full-text search
104 function InitFullSearch($dbi, $search) {
105 $search = addslashes($search);
106 $res = mysql_query("select page,hash from $dbi[table] where hash like '%$search%'", $dbi["dbc"]);
111 // iterating through database
112 function FullSearchNextMatch($dbi, $res) {
113 if($o = mysql_fetch_object($res)) {
114 $page['name'] = $o->page;
115 $page['hash'] = unserialize($o->hash);