Opened 7 years ago
Closed 6 years ago
#3022 closed defect (bug) (fixed)
BBpress import from remote database hostname:port config
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.6 | Priority: | normal |
Severity: | minor | Version: | 2.0 |
Component: | API - Importers | Keywords: | commit |
Cc: |
Description
In contrary to https://bbpress.org/forums/topic/using-the-importer/, bbPress can import from remote database. But must use Hostname:Port in the converter admin, instead of hostname and port in separate input form fields.
I'm able to use a remote MySql server as import source. Since I don't want to spin up another mysql server vm, I have another mysql instance running on the current database server using a different port from the first mysql instance at port 3306. So I must pass in the db port of the previous forum (Drupal db). The following is my config in the bbPress converter admin at http://.../wp-admin/tools.php?page=bbp-converter :
#add_settings_field# #Input# = #Form lable _bbp_converter_platform Platform = previous forum (Drupal6 for me) _bbp_converter_db_server Hostname:Port = Db Server IP or hostname _bbp_converter_db_port [NOT USED]= Db Port Use default 3306 if unsure _bbp_converter_db_name xxxxxx = Db Name old forum db name _bbp_converter_db_user yyyyyy = Db User _bbp_converter_db_pass ****** = Db Pass _bbp_converter_db_prefix Prefix = Table Prefix (blank for me)
Note that Db Port is NOT USED above, and must pass to hostname as Hostname:Port.
According to bbpress/includes/admin/converter.php:
<?php abstract class BBP_Converter_Base { public function __construct() { $this->setup_globals(); } private function setup_globals() { $this->wpdb = bbp_db(); $this->max_rows = (int) $_POST['_bbp_converter_rows']; $this->opdb = new wpdb( $_POST['_bbp_converter_db_user'], $_POST['_bbp_converter_db_pass'], $_POST['_bbp_converter_db_name'], $_POST['_bbp_converter_db_server'] ); $this->opdb->prefix = $_POST['_bbp_converter_db_prefix'];
where, new wpdb constructor can take db_name as 'hostname:port'. See source of wp-includes/wp-db.php:
<?php class wpdb { public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { public function db_connect( $allow_bail = true ) { if ( $this->use_mysqli ) { $this->dbh = mysqli_init(); // mysqli_real_connect doesn't support the host param including a port or socket // like mysql_connect does. This duplicates how mysql_connect detects a port and/or socket file. $port = null; $socket = null; $host = $this->dbhost; $port_or_socket = strstr( $host, ':' ); if ( ! empty( $port_or_socket ) ) { $host = substr( $host, 0, strpos( $host, ':' ) ); $port_or_socket = substr( $port_or_socket, 1 ); if ( 0 !== strpos( $port_or_socket, '/' ) ) { $port = intval( $port_or_socket ); $maybe_socket = strstr( $port_or_socket, ':' ); if ( ! empty( $maybe_socket ) ) { $socket = substr( $maybe_socket, 1 ); } } else { $socket = $port_or_socket; } } if ( WP_DEBUG ) { mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); } else { @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); }
so wpdb class parses out hostname:port before passing hostname and port to: http://php.net/manual/en/mysqli.real-connect.php
Object oriented style bool mysqli::real_connect ([ string $host [, string $username [, string $passwd [, string $dbname [, int $port [, string $socket [, int $flags ]]]]]]] ) Procedural style bool mysqli_real_connect ( mysqli $link [, string $host [, string $username [, string $passwd [, string $dbname [, int $port [, string $socket [, int $flags ]]]]]]] )
However, I might be missing something, but bbpress/includes/admin/converter.php doesn't use _bbp_converter_db_port at all. Whatever users input port doesn't get passed to new wpdb.
So suggest to:
1) eliminate db port from the form and instruct users to use 'hostname:port', or
2) add db port to new wpdb in converter.php:
<?php $this->opdb = new wpdb( $_POST['_bbp_converter_db_user'], $_POST['_bbp_converter_db_pass'], $_POST['_bbp_converter_db_name'], $_POST['_bbp_converter_db_server'] .':'. $_POST['_bbp_converter_db_port'] );
FYI: More discussion regarding Using wpdb to connect to a separate database:
http://wordpress.stackexchange.com/questions/1604/using-wpdb-to-connect-to-a-separate-database