From af65d827ad1d7e6bacc9fe0ac243f39dfffcd9d8 Mon Sep 17 00:00:00 2001
From: Michael R Sweet
Please report the problem to " + ."$DB_ADMIN.
\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("$SQL_QUERY
\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 $". +// +?> diff --git a/www/phplib/db.php b/www/phplib/db.php index 20c32d3..793d459 100644 --- a/www/phplib/db.php +++ b/www/phplib/db.php @@ -1,6 +1,6 @@ Database error $sqlerr\n"); - print("Please report the problem to " - ."$DB_ADMIN.
\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("Database error $sqlerrno: $sqlerr
\n"); + print("Please report the problem to " + ."webmaster@easysw.com.
\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("$SQL_QUERY
\n"); + return (mysql_query($SQL_QUERY, $DB_CONN)); - return (sqlite_query($DB_CONN, $SQL_QUERY)); +// print("SQL_QUERY: $SQL_QUERY
\n"); +// +// $result = mysql_query($SQL_QUERY, $DB_CONN); +// $count = db_count($result); +// print("Result = $count rows...
\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 $". // ?>