Switch to MySQL - SQLite not working on main server...

pull/193/head
Michael R Sweet 21 years ago
parent 02b667287c
commit af65d827ad
  1. 24
      www/data/mxml.sql
  2. 164
      www/phplib/db-sqlite.php
  3. 75
      www/phplib/db.php

@ -1,5 +1,5 @@
--
-- "$Id: mxml.sql,v 1.6 2004/05/21 02:59:52 mike Exp $"
-- "$Id: mxml.sql,v 1.7 2004/05/21 03:59:17 mike Exp $"
--
-- Database schema for the Mini-XML web pages.
--
@ -11,7 +11,7 @@
--
-- M. Sweet 05/17/2004 Initial revision.
-- M. Sweet 05/19/2004 Added link, poll, and vote tables.
--
-- M. Sweet 05/20/2004 Changes for MySQL
--
@ -23,7 +23,7 @@
--
CREATE TABLE article (
id INTEGER PRIMARY KEY, -- Article number
id INTEGER PRIMARY KEY AUTO_INCREMENT,-- Article number
is_published INTEGER, -- 0 = private, 1 = public
title VARCHAR(255), -- Title of article
abstract VARCHAR(255), -- Plain text abstract of article
@ -45,7 +45,7 @@ CREATE TABLE article (
--
CREATE TABLE carboncopy (
id INTEGER PRIMARY KEY, -- Carbon copy ID
id INTEGER PRIMARY KEY AUTO_INCREMENT,-- Carbon copy ID
url VARCHAR(255), -- File or URL
email VARCHAR(255) -- Email address
);
@ -60,7 +60,7 @@ CREATE TABLE carboncopy (
--
CREATE TABLE comment (
id INTEGER PRIMARY KEY, -- Comment ID number
id INTEGER PRIMARY KEY AUTO_INCREMENT,-- Comment ID number
parent_id INTEGER, -- Parent comment ID number (reply-to)
status INTEGER, -- Moderation status, 0 = dead to 5 = great
url VARCHAR(255), -- File/link this comment applies to
@ -79,7 +79,7 @@ CREATE TABLE comment (
--
CREATE TABLE link (
id INTEGER PRIMARY KEY, -- Link ID number
id INTEGER PRIMARY KEY AUTO_INCREMENT,-- Link ID number
parent_id INTEGER, -- Parent link ID or 0 for top-level
is_category INTEGER, -- 0 = listing, 1 = category
is_published INTEGER, -- 0 = private, 1 = public
@ -112,7 +112,7 @@ CREATE TABLE link (
--
CREATE TABLE poll (
id INTEGER PRIMARY KEY, -- Poll ID number
id INTEGER PRIMARY KEY AUTO_INCREMENT,-- Poll ID number
is_published INTEGER, -- 0 = private, 1 = public
poll_type INTEGER, -- 0 = pick one, 1 = pick many
question VARCHAR(255), -- Question plain text
@ -151,7 +151,7 @@ CREATE TABLE poll (
--
CREATE TABLE str (
id INTEGER PRIMARY KEY, -- STR number
id INTEGER PRIMARY KEY AUTO_INCREMENT,-- STR number
master_id INTEGER, -- "Duplicate of" number
is_published INTEGER, -- 0 = private, 1 = public
status INTEGER, -- 1 = closed/resolved,
@ -179,7 +179,7 @@ CREATE TABLE str (
--
CREATE TABLE strfile (
id INTEGER PRIMARY KEY, -- File ID
id INTEGER PRIMARY KEY AUTO_INCREMENT,-- File ID
str_id INTEGER, -- STR number
is_published INTEGER, -- 0 = private, 1 = public
filename VARCHAR(255), -- Name of file
@ -195,7 +195,7 @@ CREATE TABLE strfile (
--
CREATE TABLE strtext (
id INTEGER PRIMARY KEY, -- Text ID
id INTEGER PRIMARY KEY AUTO_INCREMENT,-- Text ID
str_id INTEGER, -- STR number
is_published INTEGER, -- 0 = private, 1 = public
contents TEXT, -- Text message
@ -213,7 +213,7 @@ CREATE TABLE strtext (
--
CREATE TABLE users (
id INTEGER PRIMARY KEY, -- ID
id INTEGER PRIMARY KEY AUTO_INCREMENT,-- ID
is_published INTEGER, -- 0 = private, 1 = public
name VARCHAR(255), -- Login name
email VARCHAR(255), -- Name/email address
@ -238,5 +238,5 @@ CREATE TABLE vote (
);
--
-- End of "$Id: mxml.sql,v 1.6 2004/05/21 02:59:52 mike Exp $".
-- End of "$Id: mxml.sql,v 1.7 2004/05/21 03:59:17 mike Exp $".
--

@ -0,0 +1,164 @@
<?php
//
// "$Id: db-sqlite.php,v 1.1 2004/05/21 03:59:17 mike Exp $"
//
// Common database include file for PHP web pages. This file can be used
// to abstract the specific database in use...
//
// This version is for the SQLite database and module.
//
// This file should be included using "include_once"...
//
// Contents:
//
// db_close() - Close the database.
// db_count() - Return the number of rows in a query result.
// db_escape() - Escape special chars in string for query.
// db_free() - Free a database query result...
// db_insert_id() - Return the ID of the last inserted record.
// db_next() - Fetch the next row of a result set and return it as
// an object.
// db_query() - Run a SQL query and return the result or 0 on error.
// db_seek() - Seek to a specific row within a result.
//
// Some static database access info.
$DB_ADMIN = "webmaster@easysw.com";
$DB_HOST = "";
$DB_NAME = "mxml";
$DB_USER = "";
$DB_PASSWORD = "";
// Make sure that the module is loaded...
if (!extension_loaded("sqlite"))
{
dl("sqlite.so");
}
// Open the SQLite database defined above...
$DB_CONN = sqlite_open("data/$DB_NAME.db", 0666, $sqlerr);
if (!$DB_CONN)
{
// Unable to open, display an error message...
print("<p>Database error $sqlerr</p>\n");
print("<p>Please report the problem to <a href='mailto:$DB_ADMIN'>"
."$DB_ADMIN</a>.</p>\n");
exit(1);
}
//
// 'db_close()' - Close the database.
//
function
db_close()
{
global $DB_CONN;
sqlite_close($DB_CONN);
$DB_CONN = false;
}
//
// 'db_count()' - Return the number of rows in a query result.
//
function // O - Number of rows in result
db_count($result) // I - Result of query
{
if ($result)
return (sqlite_num_rows($result));
else
return (0);
}
//
// 'db_escape()' - Escape special chars in string for query.
//
function // O - Quoted string
db_escape($str) // I - String
{
return (sqlite_escape_string($str));
}
//
// 'db_free()' - Free a database query result...
//
function
db_free($result) // I - Result of query
{
// Nothing to do, as SQLite doesn't free results...
}
//
// 'db_insert_id()' - Return the ID of the last inserted record.
//
function // O - ID number
db_insert_id()
{
global $DB_CONN;
return (sqlite_last_insert_rowid($DB_CONN));
}
//
// 'db_next()' - Fetch the next row of a result set and return it as an object.
//
function // O - Row object or NULL at end
db_next($result) // I - Result of query
{
if ($result)
return (sqlite_fetch_array($result, SQLITE_ASSOC, TRUE));
else
return (NULL);
}
//
// 'db_query()' - Run a SQL query and return the result or 0 on error.
//
function // O - Result of query or NULL
db_query($SQL_QUERY) // I - SQL query string
{
global $DB_CONN;
// print("<p>$SQL_QUERY</p>\n");
return (sqlite_query($DB_CONN, $SQL_QUERY));
}
//
// 'db_seek()' - Seek to a specific row within a result.
//
function // O - TRUE on success, FALSE otherwise
db_seek($result, // I - Result of query
$index = 0) // I - Row number (0 = first row)
{
if ($result)
return (sqlite_seek($result, $index));
else
return (FALSE);
}
//
// End of "$Id: db-sqlite.php,v 1.1 2004/05/21 03:59:17 mike Exp $".
//
?>

@ -1,6 +1,6 @@
<?php
//
// "$Id: db.php,v 1.4 2004/05/19 00:57:33 mike Exp $"
// "$Id: db.php,v 1.5 2004/05/21 03:59:17 mike Exp $"
//
// Common database include file for PHP web pages. This file can be used
// to abstract the specific database in use...
@ -24,44 +24,32 @@
// Some static database access info.
$DB_ADMIN = "webmaster@easysw.com";
$DB_HOST = "";
$DB_HOST = "localhost";
$DB_NAME = "mxml";
$DB_USER = "";
$DB_USER = "mike";
$DB_PASSWORD = "";
//
// Connect to the MySQL server using DB_HOST, DB_USER, DB_PASSWORD
// that are set above...
//
// Make sure that the module is loaded...
if (!extension_loaded("sqlite"))
{
dl("sqlite.so");
}
// Open the SQLite database defined above...
$DB_CONN = sqlite_open("data/$DB_NAME.db", 0666, $sqlerr);
$DB_CONN = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD);
if (!$DB_CONN)
if ($DB_CONN)
{
// Unable to open, display an error message...
print("<p>Database error $sqlerr</p>\n");
print("<p>Please report the problem to <a href='mailto:$DB_ADMIN'>"
."$DB_ADMIN</a>.</p>\n");
exit(1);
// Connected to server; select the database...
mysql_select_db($DB_NAME, $DB_CONN);
}
//
// 'db_close()' - Close the database.
//
function
db_close()
else
{
global $DB_CONN;
// Unable to connect; display an error message...
$sqlerrno = mysql_errno();
$sqlerr = mysql_error();
sqlite_close($DB_CONN);
$DB_CONN = false;
print("<p>Database error $sqlerrno: $sqlerr</p>\n");
print("<p>Please report the problem to <a href='mailto:webmaster@easysw.com'>"
."webmaster@easysw.com</a>.</p>\n");
}
@ -73,7 +61,7 @@ function // O - Number of rows in result
db_count($result) // I - Result of query
{
if ($result)
return (sqlite_num_rows($result));
return (mysql_num_rows($result));
else
return (0);
}
@ -86,7 +74,7 @@ db_count($result) // I - Result of query
function // O - Quoted string
db_escape($str) // I - String
{
return (sqlite_escape_string($str));
return (mysql_escape_string($str));
}
@ -97,7 +85,8 @@ db_escape($str) // I - String
function
db_free($result) // I - Result of query
{
// Nothing to do, as SQLite doesn't free results...
if ($result)
mysql_free_result($result);
}
@ -110,7 +99,7 @@ db_insert_id()
{
global $DB_CONN;
return (sqlite_last_insert_rowid($DB_CONN));
return (mysql_insert_id($DB_CONN));
}
@ -122,7 +111,7 @@ function // O - Row object or NULL at end
db_next($result) // I - Result of query
{
if ($result)
return (sqlite_fetch_array($result, SQLITE_ASSOC, TRUE));
return (mysql_fetch_array($result));
else
return (NULL);
}
@ -135,11 +124,17 @@ db_next($result) // I - Result of query
function // O - Result of query or NULL
db_query($SQL_QUERY) // I - SQL query string
{
global $DB_CONN;
global $DB_NAME, $DB_CONN;
// print("<p>$SQL_QUERY</p>\n");
return (mysql_query($SQL_QUERY, $DB_CONN));
return (sqlite_query($DB_CONN, $SQL_QUERY));
// print("<p>SQL_QUERY: $SQL_QUERY</p>\n");
//
// $result = mysql_query($SQL_QUERY, $DB_CONN);
// $count = db_count($result);
// print("<p>Result = $count rows...</p>\n");
//
// return ($result);
}
@ -152,13 +147,13 @@ db_seek($result, // I - Result of query
$index = 0) // I - Row number (0 = first row)
{
if ($result)
return (sqlite_seek($result, $index));
return (mysql_data_seek($result, $index));
else
return (FALSE);
}
//
// End of "$Id: db.php,v 1.4 2004/05/19 00:57:33 mike Exp $".
// End of "$Id: db.php,v 1.5 2004/05/21 03:59:17 mike Exp $".
//
?>

Loading…
Cancel
Save