[wp-trac] [WordPress Trac] #32798: Add support for mysql named pipe (windows os)
WordPress Trac
noreply at wordpress.org
Fri Jun 26 16:11:01 UTC 2015
#32798: Add support for mysql named pipe (windows os)
----------------------------+-----------------------------
Reporter: bogdan.ionescu | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: 4.2.2
Severity: normal | Keywords:
Focuses: |
----------------------------+-----------------------------
This patch allows the connection via pipe into the windows operating
system.
Configuration needed:
'''MySQL 5.6 file: my.ini'''
{{{
#!ini
[mysqld]
#
# ... other settings here ...
#
skip-networking
enable-named-pipe
socket="mysql56.pipe"
[client]
#
# ... other settings here ...
#
pipe
socket="mysql56.pipe"
}}}
'''Wordpress file: wp-config.php'''
{{{
#!php
<?php
#
# ... other settings here ...
#
/** The name of the database for WordPress */
define('DB_NAME', 'wp_demo1');
/** MySQL database username */
define('DB_USER', 'wp_demo1');
/** MySQL database password */
define('DB_PASSWORD', 'pa$$w0rd');
/** MySQL hostname */
define('DB_HOST', '.:\\\\.\\pipe\\mysql56.pipe'); # syntax =
".:\\.\pipe\name.pipe"
/** MySQLi extension (optional) */
#define('WP_USE_EXT_MYSQL', false); # for mysqli set to false
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', 'utf8_general_ci');
}}}
'''Wordpress patch: wp-db.php'''
{{{
#!diff
Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php (revision 32925)
+++ src/wp-includes/wp-db.php (working copy)
@@ -1414,31 +1414,35 @@
* Deprecated in 3.9+ when using MySQLi. No equivalent
* $new_link parameter exists for mysqli_* functions.
*/
$new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK :
true;
$client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ?
MYSQL_CLIENT_FLAGS : 0;
+ $port = null;
+ $socket = null;
+ $host = $this->dbhost;
+ $port_or_socket = strstr( $host, ':' );
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;
+ switch(0)
+ {
+ case strpos( $port_or_socket, '/'
): # linux socket
+ case strpos( $port_or_socket,
'\\'): # windows pipe
+ $socket = $port_or_socket;
+ break;
+ default:
+ $port = intval(
$port_or_socket );
+ $maybe_socket = strstr(
$port_or_socket, ':' );
+ if ( ! empty(
$maybe_socket ) ) {
+ $socket = substr(
$maybe_socket, 1 );
+ }
}
}
if ( WP_DEBUG ) {
mysqli_real_connect( $this->dbh, $host,
$this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
@@ -1468,10 +1472,20 @@
$this->use_mysqli = false;
$this->db_connect();
}
}
} else {
+ 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, '\\' )) #
windows pipe
+ {
+ ini_set('mysql.default_host',
$host);
+ ini_set('mysql.default_socket',
$port_or_socket);
+ }
+ }
+
if ( WP_DEBUG ) {
$this->dbh = mysql_connect( $this->dbhost,
$this->dbuser, $this->dbpassword, $new_link, $client_flags );
} else {
$this->dbh = @mysql_connect(
$this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags
);
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32798>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list