From 7c4d76a0b6ecb83e8d0f5ce1c7d46552c2196ec5 Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Sat, 8 Apr 2017 13:33:13 -0600 Subject: [PATCH] Fix connection failure handling If the connection fails, bail early. Otherwise the processing of the queued SQL statements will cause an infinite loop by continually pushing the same statement into the queue due to lack of connection. Also add a local variable for the connection for clarity and performance. Signed-off-by: Kevin Locke --- pg4wp/driver_pgsql.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pg4wp/driver_pgsql.php b/pg4wp/driver_pgsql.php index 0536b95..9b271c6 100644 --- a/pg4wp/driver_pgsql.php +++ b/pg4wp/driver_pgsql.php @@ -91,15 +91,15 @@ $pg_connstr = $GLOBALS['pg4wp_connstr'].' dbname='.$dbname; // Note: pg_connect returns existing connection for same connstr - $GLOBALS['pg4wp_conn'] = pg_connect($pg_connstr); - - if( $GLOBALS['pg4wp_conn']) - { - $ver = pg_version($GLOBALS['pg4wp_conn']); - if( isset($ver['server'])) - $GLOBALS['pg4wp_version'] = $ver['server']; - } - + $GLOBALS['pg4wp_conn'] = $conn = pg_connect($pg_connstr); + + if( !$conn) + return $conn; + + $ver = pg_version($conn); + if( isset($ver['server'])) + $GLOBALS['pg4wp_version'] = $ver['server']; + // Now we should be connected, we "forget" about the connection parameters (if this is not a "test" connection) if( !defined('WP_INSTALLING') || !WP_INSTALLING) $GLOBALS['pg4wp_connstr'] = ''; @@ -109,7 +109,7 @@ foreach( $GLOBALS['pg4wp_pre_sql'] as $sql2run) wpsql_query( $sql2run); - return $GLOBALS['pg4wp_conn']; + return $conn; } function wpsql_fetch_array($result)