Closed cliffordp closed 3 years ago
I'm trying to figure this out as well. Any ideas?
@cliffordp
I did some digging into the CLI code last night. The GUI appears to work in Local; I think because it exists/runs within the overall container of what Local has setup for the site you're running locally. However, the CLI didn't work. Perhaps because I'm calling a different, system-level PHP binary for running the CLI script.
Updated this function around line #490 in srdb.class.php
/**
* Sets up database connection using PDO
*
* @return PDO|bool
*/
public function connect_pdo() {
if(preg_match('/^\/.*/', $this->host)) {
$unix_socket = $this->host;
$pdo_string = "mysql:dbname={$this->name};unix_socket={$unix_socket}";
} else {
$pdo_string = "mysql:host={$this->host};port={$this->port};dbname={$this->name}";
}
try {
$connection = new PDO( $pdo_string, $this->user, $this->pass );
} catch( PDOException $e ) {
$this->add_error( $e->getMessage(), 'db' );
$connection = false;
}
// check if there's a problem with our database at this stage
if ( $connection && ! $connection->query( 'SHOW TABLES' ) ) {
$error_info = $connection->errorInfo();
if ( !empty( $error_info ) && is_array( $error_info ) )
$this->add_error( array_pop( $error_info ), 'db' ); // Array pop will only accept a $var..
$connection = false;
}
return $connection;
}
I hope this helps! I'm going to submit a PR on Github and see where that gets us.
that's great! tbh, I think the WP-CLI command is sufficient: https://developer.wordpress.org/cli/commands/search-replace/
nice you found a way to use sockets, let's close this.
https://localwp.com/ uses a Socket on Mac instead of an IP + Port. Would be nice to use it with that tool.