mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-07-30 09:47:14 +02:00
Rewrote database connection handling so that Wordpress installation can now tell you if your username and password are wrong.
Added support for connecting without a password but requiring PG4WP_INSECURE to be set to true. git-svn-id: https://plugins.svn.wordpress.org/postgresql-for-wordpress/trunk@419913 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
@ -21,7 +21,8 @@
|
|||||||
$GLOBALS['pg4wp_numrows'] = '10';
|
$GLOBALS['pg4wp_numrows'] = '10';
|
||||||
$GLOBALS['pg4wp_ins_table'] = '';
|
$GLOBALS['pg4wp_ins_table'] = '';
|
||||||
$GLOBALS['pg4wp_ins_field'] = '';
|
$GLOBALS['pg4wp_ins_field'] = '';
|
||||||
$GLOBALS['pg4wp_user'] = $GLOBALS['pg4wp_password'] = $GLOBALS['pg4wp_server'] = '';
|
$GLOBALS['pg4wp_connstr'] = '';
|
||||||
|
$GLOBALS['pg4wp_conn'] = false;
|
||||||
|
|
||||||
function wpsql_num_rows($result)
|
function wpsql_num_rows($result)
|
||||||
{ return pg_num_rows($result); }
|
{ return pg_num_rows($result); }
|
||||||
@ -47,39 +48,50 @@
|
|||||||
function wpsql_data_seek($result, $offset)
|
function wpsql_data_seek($result, $offset)
|
||||||
{ return pg_result_seek ( $result, $offset ); }
|
{ return pg_result_seek ( $result, $offset ); }
|
||||||
function wpsql_error()
|
function wpsql_error()
|
||||||
{ if( $GLOBALS['pg4wp_user'] == '') return pg_last_error(); else return ''; }
|
{ if( $GLOBALS['pg4wp_conn']) return pg_last_error(); else return ''; }
|
||||||
function wpsql_fetch_assoc($result) { return pg_fetch_assoc($result); }
|
function wpsql_fetch_assoc($result) { return pg_fetch_assoc($result); }
|
||||||
function wpsql_escape_string($s) { return pg_escape_string($s); }
|
function wpsql_escape_string($s) { return pg_escape_string($s); }
|
||||||
function wpsql_get_server_info() { return '5.0.30'; } // Just want to fool wordpress ...
|
function wpsql_get_server_info() { return '5.0.30'; } // Just want to fool wordpress ...
|
||||||
function wpsql_result($result, $i, $fieldname)
|
function wpsql_result($result, $i, $fieldname)
|
||||||
{ return pg_fetch_result($result, $i, $fieldname); }
|
{ return pg_fetch_result($result, $i, $fieldname); }
|
||||||
|
|
||||||
// This is a fake connection
|
// This is a fake connection except during installation
|
||||||
function wpsql_connect($dbserver, $dbuser, $dbpass)
|
function wpsql_connect($dbserver, $dbuser, $dbpass)
|
||||||
{
|
{
|
||||||
$GLOBALS['pg4wp_user'] = $dbuser;
|
$GLOBALS['pg4wp_connstr'] = '';
|
||||||
$GLOBALS['pg4wp_password'] = $dbpass;
|
if( !empty( $dbserver))
|
||||||
$GLOBALS['pg4wp_server'] = $dbserver;
|
$GLOBALS['pg4wp_connstr'] .= ' host='.$dbserver;
|
||||||
|
if( !empty( $dbuser))
|
||||||
|
$GLOBALS['pg4wp_connstr'] .= ' user='.$dbuser;
|
||||||
|
if( !empty( $dbpass))
|
||||||
|
$GLOBALS['pg4wp_connstr'] .= ' password='.$dbpass;
|
||||||
|
elseif( !PG4WP_INSECURE)
|
||||||
|
wp_die( 'Connecting to your PostgreSQL database without a password is considered insecure.
|
||||||
|
<br />If you want to do it anyway, please set "PG4WP_INSECURE" to true in your "db.php" file.' );
|
||||||
|
|
||||||
|
// While installing, we test the connection to 'template0' (as we don't know the effective dbname yet)
|
||||||
|
if( defined('WP_INSTALLING') && WP_INSTALLING)
|
||||||
|
return wpsql_select_db( 'template1');
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The effective connection happens here
|
||||||
function wpsql_select_db($dbname, $connection_id = 0)
|
function wpsql_select_db($dbname, $connection_id = 0)
|
||||||
{
|
{
|
||||||
$pg_user = $GLOBALS['pg4wp_user'];
|
$pg_connstr = $GLOBALS['pg4wp_connstr'].' dbname='.$dbname;
|
||||||
$pg_password = $GLOBALS['pg4wp_password'];
|
|
||||||
$pg_server = $GLOBALS['pg4wp_server'];
|
$GLOBALS['pg4wp_conn'] = pg_connect($pg_connstr);
|
||||||
if( empty( $pg_server))
|
|
||||||
$GLOBALS['pg4wp_conn'] = pg_connect("user=$pg_user password=$pg_password dbname=$dbname");
|
// Now we should be connected, we "forget" about the connection parameters (if this is not a "test" connection
|
||||||
else
|
if( !defined('WP_INSTALLING') || !WP_INSTALLING)
|
||||||
$GLOBALS['pg4wp_conn'] = pg_connect("host=$pg_server user=$pg_user password=$pg_password dbname=$dbname");
|
$GLOBALS['pg4wp_connstr'] = '';
|
||||||
// Now we should be connected, we "forget" about the connection parameters
|
|
||||||
$GLOBALS['pg4wp_user'] = '';
|
|
||||||
$GLOBALS['pg4wp_password'] = '';
|
|
||||||
$GLOBALS['pg4wp_server'] = '';
|
|
||||||
// Execute early transmitted commands if needed
|
// Execute early transmitted commands if needed
|
||||||
if( isset($GLOBALS['pg4wp_pre_sql']) && !empty($GLOBALS['pg4wp_pre_sql']))
|
if( isset($GLOBALS['pg4wp_pre_sql']) && !empty($GLOBALS['pg4wp_pre_sql']))
|
||||||
foreach( $GLOBALS['pg4wp_pre_sql'] as $sql2run)
|
foreach( $GLOBALS['pg4wp_pre_sql'] as $sql2run)
|
||||||
wpsql_query( $sql2run);
|
wpsql_query( $sql2run);
|
||||||
|
|
||||||
return $GLOBALS['pg4wp_conn'];
|
return $GLOBALS['pg4wp_conn'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +107,7 @@
|
|||||||
|
|
||||||
function wpsql_query($sql)
|
function wpsql_query($sql)
|
||||||
{
|
{
|
||||||
if( !isset($GLOBALS['pg4wp_conn']))
|
if( !$GLOBALS['pg4wp_conn'])
|
||||||
{
|
{
|
||||||
// Catch SQL to be executed as soon as connected
|
// Catch SQL to be executed as soon as connected
|
||||||
$GLOBALS['pg4wp_pre_sql'][] = $sql;
|
$GLOBALS['pg4wp_pre_sql'][] = $sql;
|
||||||
|
@ -25,10 +25,7 @@ If you need/wish support for another database, please feel free to contact the a
|
|||||||
|
|
||||||
== Installation ==
|
== Installation ==
|
||||||
|
|
||||||
Whereas it appears in the control panel, enabling/disabling this plugin through the control panel won't do anything.
|
You have to install PG4WP *before* setting up your WordPress installation for things to work properly.
|
||||||
You have to install it before setting up your WordPress installation for things to work properly.
|
|
||||||
|
|
||||||
This section describes how to install the plugin and get it working.
|
|
||||||
This is because the database needs to be up and running before any plugin can be loaded.
|
This is because the database needs to be up and running before any plugin can be loaded.
|
||||||
|
|
||||||
1. Unzip the files and put the `pg4wp` directory in your `/wp-content` directory.
|
1. Unzip the files and put the `pg4wp` directory in your `/wp-content` directory.
|
||||||
@ -50,6 +47,9 @@ There is no screenshot for this plugin
|
|||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
* Rewrote database connection handling so Wordpress installation can tell you when you username and password are wrong
|
||||||
|
* Support for using an empty password for database connection
|
||||||
|
Note : this requires setting 'PG4WP_INSECURE' to true in `db.php` for PG4WP to accept this
|
||||||
* Some code optimizations
|
* Some code optimizations
|
||||||
|
|
||||||
= 1.2.0b1 =
|
= 1.2.0b1 =
|
||||||
|
Reference in New Issue
Block a user