From a51d5b5532530f474499c0c25068f8c105499154 Mon Sep 17 00:00:00 2001 From: hawk__ Date: Mon, 1 Aug 2011 21:43:06 +0000 Subject: [PATCH] Corrections for WP 3.1+ support git-svn-id: https://plugins.svn.wordpress.org/postgresql-for-wordpress/trunk@418075 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- pg4wp/db.php | 6 ++++++ pg4wp/driver_pgsql.php | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pg4wp/db.php b/pg4wp/db.php index de99e29..83ac6cc 100644 --- a/pg4wp/db.php +++ b/pg4wp/db.php @@ -45,4 +45,10 @@ $replaces = array( ); eval( str_replace( array_keys($replaces), array_values($replaces), file_get_contents(ABSPATH.'/wp-includes/wp-db.php'))); require_once( ABSPATH.'/wp-includes/wp-db.php'); + +if (! isset($wpdb)) { + // Create wpdb object if not already done + $wpdb = new wpdb2( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); +} + } // Protection against multiple loading \ No newline at end of file diff --git a/pg4wp/driver_pgsql.php b/pg4wp/driver_pgsql.php index f14da05..8db9a5a 100644 --- a/pg4wp/driver_pgsql.php +++ b/pg4wp/driver_pgsql.php @@ -70,14 +70,18 @@ $pg_password = $GLOBALS['pg4wp_password']; $pg_server = $GLOBALS['pg4wp_server']; if( empty( $pg_server)) - $conn = pg_connect("user=$pg_user password=$pg_password dbname=$dbname"); + $GLOBALS['pg4wp_conn'] = pg_connect("user=$pg_user password=$pg_password dbname=$dbname"); else - $conn = pg_connect("host=$pg_server user=$pg_user password=$pg_password dbname=$dbname"); + $GLOBALS['pg4wp_conn'] = pg_connect("host=$pg_server user=$pg_user password=$pg_password dbname=$dbname"); // Now we should be connected, we "forget" about the connection parameters $GLOBALS['pg4wp_user'] = ''; $GLOBALS['pg4wp_password'] = ''; $GLOBALS['pg4wp_server'] = ''; - return $conn; + // Execute early transmitted commands if needed + if( isset($GLOBALS['pg4wp_pre_sql']) && !empty($GLOBALS['pg4wp_pre_sql'])) + foreach( $GLOBALS['pg4wp_pre_sql'] as $sql2run) + wpsql_query( $sql2run); + return $GLOBALS['pg4wp_conn']; } function wpsql_fetch_array($result) @@ -92,6 +96,12 @@ function wpsql_query($sql) { + if( !isset($GLOBALS['pg4wp_conn'])) + { + // Catch SQL to be executed as soon as connected + $GLOBALS['pg4wp_pre_sql'][] = $sql; + return true; + } global $table_prefix; $logto = 'queries'; // This is used to catch the number of rows returned by the last "SELECT" REQUEST