diff -ruwB feed-on-feeds-svn/classes/fof-prefs.php feed-on-feeds-mdb2_pgsql/classes/fof-prefs.php
--- feed-on-feeds-svn/classes/fof-prefs.php 2008-02-24 20:52:38.000000000 +0100
+++ feed-on-feeds-mdb2_pgsql/classes/fof-prefs.php 2008-03-26 15:13:41.000000000 +0100
@@ -25,7 +25,7 @@
$this->user_id = $user_id;
$result = fof_safe_query("select user_prefs from $FOF_USER_TABLE where user_id = %d", $user_id);
- $row = mysql_fetch_array($result);
+ $row = $result -> fetchRow();
$prefs = unserialize($row['user_prefs']);
if(!is_array($prefs)) $prefs = array();
$this->prefs = $prefs;
@@ -33,7 +33,7 @@
if($user_id != 1)
{
$result = fof_safe_query("select user_prefs from $FOF_USER_TABLE where user_id = 1");
- $row = mysql_fetch_array($result);
+ $row = $result -> fetchRow();
$admin_prefs = unserialize($row['user_prefs']);
if(!is_array($admin_prefs)) $admin_prefs = array();
$this->admin_prefs = $admin_prefs;
diff -ruwB feed-on-feeds-svn/fof-config-sample.php feed-on-feeds-mdb2_pgsql/fof-config-sample.php
--- feed-on-feeds-svn/fof-config-sample.php 2008-02-24 20:52:39.000000000 +0100
+++ feed-on-feeds-mdb2_pgsql/fof-config-sample.php 2008-02-24 19:39:01.000000000 +0100
@@ -15,6 +15,7 @@
// Database connection information. Host, username, password, database name.
+define('FOF_DB_BACKEND', "pgsql"); // pgsql, mysql, ...
define('FOF_DB_HOST', "host.example.com");
define('FOF_DB_USER', "username");
define('FOF_DB_PASS', "password");
diff -ruwB feed-on-feeds-svn/fof-db.php feed-on-feeds-mdb2_pgsql/fof-db.php
--- feed-on-feeds-svn/fof-db.php 2008-02-24 20:52:39.000000000 +0100
+++ feed-on-feeds-mdb2_pgsql/fof-db.php 2008-03-26 15:23:35.000000000 +0100
@@ -12,6 +12,8 @@
*
*/
+include_once('MDB2.php');
+
$FOF_FEED_TABLE = FOF_FEED_TABLE;
$FOF_ITEM_TABLE = FOF_ITEM_TABLE;
$FOF_ITEM_TAG_TABLE = FOF_ITEM_TAG_TABLE;
@@ -27,23 +29,35 @@
{
global $fof_connection;
- $fof_connection = mysql_connect(FOF_DB_HOST, FOF_DB_USER, FOF_DB_PASS) or die("
Cannot connect to database. Please update configuration in fof-config.php. Mysql says: " . mysql_error() . "");
- mysql_select_db(FOF_DB_DBNAME, $fof_connection) or die("
Cannot select database. Please update configuration in fof-config.php. Mysql says: " . mysql_error() . "");
+ $fof_connection = MDB2::connect(FOF_DB_BACKEND."://".FOF_DB_USER.":".FOF_DB_PASS."@".FOF_DB_HOST."/".FOF_DB_DBNAME);
+ if (PEAR::isError($fof_connection)) {
+ die("Cannot connect to the SQL.
SQL says: " . $fof_connection->getMessage() . " (" . $fof_connection->getCode() . ")");
+ }
+
+ $fof_connection->setFetchMode(MDB2_FETCHMODE_ASSOC);
+
+ // Manager needed to vacuum/optimize the database and to alter it (during install step)
+ $fof_connection->loadModule('Manager', null, true);
}
function fof_db_optimize()
{
- global $FOF_FEED_TABLE, $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE, $FOF_SUBSCRIPTION_TABLE, $FOF_TAG_TABLE, $FOF_USER_TABLE;
+ global $fof_connection;
- fof_db_query("optimize table $FOF_FEED_TABLE, $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE, $FOF_SUBSCRIPTION_TABLE, $FOF_TAG_TABLE, $FOF_USER_TABLE");
+ // vacuum needs >=Pear::MDB2-1.5.0_beta1
+ if (Pear::isError($fof_connection->manager->vacuum(null, array(analyze=>true)))) {
+ die("Cannot vacuum database. SQL says: ". $result->getMessage() ." (" . $result->getCode() . ") - " . $result->getUserinfo());
+ }
}
function fof_safe_query(/* $query, [$args...]*/)
{
+ global $fof_connection;
+
$args = func_get_args();
$query = array_shift($args);
if(is_array($args[0])) $args = $args[0];
- $args = array_map('mysql_real_escape_string', $args);
+ $args = array_map('addslashes', $args);
$query = vsprintf($query, $args);
return fof_db_query($query);
@@ -56,10 +70,12 @@
list($usec, $sec) = explode(" ", microtime());
$t1 = (float)$sec + (float)$usec;
- $result = mysql_query($sql, $fof_connection);
+ $result = $fof_connection->query($sql);
+
- if(is_resource($result)) $num = mysql_num_rows($result);
- if($result) $affected = mysql_affected_rows();
+ if($result && !PEAR::isError($result)) $num = ($result->numRows());
+ // No affectedRows method in PEAR::MDB2
+ //if($result) $affected = $fof_connection->affectedRows();
list($usec, $sec) = explode(" ", microtime());
$t2 = (float)$sec + (float)$usec;
@@ -73,12 +89,12 @@
}
else
{
- if(mysql_errno())
+ if(PEAR::isError($result))
{
//echo "
"; //print_r(debug_backtrace()); //echo ""; - die("Cannot query database. Have you run
install.php
to create or upgrade your installation? MySQL says: ". mysql_error() . "");
+ die("Cannot query database. Have you run install.php
to create or upgrade your installation? install.php
to create or upgrade your installation? MySQL says: ". mysql_error() . "");
+ $result = fof_db_query($sql);
}
}
@@ -664,18 +683,9 @@
foreach($items as $item)
{
- $sql[] = sprintf("(%d, %d, %d)", $user_id, $tag_id, $item);
- }
-
- $values = implode ( ",", $sql );
-
+ $values = sprintf("(%d, %d, %d)", $user_id, $tag_id, $item);
$sql = "insert into $FOF_ITEM_TAG_TABLE (user_id, tag_id, item_id) values " . $values;
-
- $result = fof_db_query($sql, 1);
-
- if(!$result && (mysql_errno() != 1062))
- {
- die("Cannot query database. Have you run install.php
to create or upgrade your installation? MySQL says: ". mysql_error() . "");
+ $result = fof_db_query($sql);
}
}
@@ -743,7 +753,7 @@
{
global $FOF_USER_TABLE;
$result = fof_safe_query("select user_id from $FOF_USER_TABLE where user_name = '%s'", $username);
- $row = mysql_fetch_array($result);
+ $row = $result->fetchRow();
return $row['user_id'];
}
@@ -771,14 +781,15 @@
{
global $FOF_USER_TABLE, $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE, $fof_connection, $fof_user_id, $fof_user_name, $fof_user_level;
+
$result = fof_safe_query("select * from $FOF_USER_TABLE where user_name = '%s' and user_password_hash = '%s'", $user_name, $user_password_hash);
- if(mysql_num_rows($result) == 0)
+ if($result -> numRows() == 0)
{
return false;
}
- $row = mysql_fetch_array($result);
+ $row = $result->fetchRow();
$fof_user_name = $row['user_name'];
$fof_user_id = $row['user_id'];
diff -ruwB feed-on-feeds-svn/fof-main.php feed-on-feeds-mdb2_pgsql/fof-main.php
--- feed-on-feeds-svn/fof-main.php 2008-02-24 20:52:39.000000000 +0100
+++ feed-on-feeds-mdb2_pgsql/fof-main.php 2008-03-26 15:12:51.000000000 +0100
@@ -511,7 +511,7 @@
{
fof_db_delete_subscription($user_id, $feed_id);
- if(mysql_num_rows(fof_get_subscribed_users($feed_id)) == 0)
+ if(fof_get_subscribed_users($feed_id)->numRows() == 0)
{
fof_db_delete_feed($feed_id);
}
@@ -903,7 +903,7 @@
$in = implode ( ", ", $ids );
global $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE;
- $sql = "select item_id, item_cached from $FOF_ITEM_TABLE where feed_id = $feed_id and item_id not in ($in) order by item_cached desc limit $count, 1000000000";
+ $sql = "select item_id, item_cached from $FOF_ITEM_TABLE where feed_id = $feed_id and item_id not in ($in) order by item_cached desc offset $countlimit 1000000000";
$result = fof_db_query($sql);
while($row = fof_db_get_row($result))
diff -ruwB feed-on-feeds-svn/install.php feed-on-feeds-mdb2_pgsql/install.php
--- feed-on-feeds-svn/install.php 2008-02-24 20:52:39.000000000 +0100
+++ feed-on-feeds-mdb2_pgsql/install.php 2008-03-26 15:20:38.000000000 +0100
@@ -12,12 +12,11 @@
*
*/
+@include_once('MDB2.php');
+
$fof_no_login = true;
$fof_installer = true;
-include_once("fof-main.php");
-
-fof_set_content_type();
// compatibility testing code lifted from SimplePie
@@ -38,10 +37,40 @@
return $curl;
}
+
+// Test if a field is present in the given table
+function isFieldPresent($table, $field) {
+ $present=false;
+ global $fof_connection;
+
+ $fields = $fof_connection -> manager -> listTableFields($table);
+
+ if (PEAR::isError($fields)) {
+ exit ("Error while testing for field presence. SQL says: " . $fields->getMessage() . "