Categories
Strava

Town ride

Cycled 5.7 kilometers in 17 minutes.

Categories
Strava

Slippery when leafy

Cycled 17.1 kilometers in 1 hours, 13 minutes.

Categories
Strava

Lunch Run

Ran 5.2 kilometers in 27 minutes.

Categories
Uncategorized

WP Dev with Docker

I got stuck for a bit today on how to configure a PHP PDO connection in a Docker based WordPress dev env. Here’s the function…

/**
 * Get the database connection
 * @return \PDO database connection instance
 */
public function get_connection() {
    $dbname = \TMSC\tmsc_sync()::$tms_db_name;
    $username = \TMSC\tmsc_sync()::$tms_db_user;
    $password = \TMSC\tmsc_sync()::$tms_db_password;
    // Build the DSN string
    $host = \TMSC\tmsc_sync()::$tms_db_host;
    $port = '3306';
    if ( strpos( $host, ':' ) ) {
        list( $host, $port ) = explode( ':', $host );
    }

    $dsn = "mysql:host={$host};port={$port};dbname={$dbname}";

    $connection = new \PDO( $dsn, $username, $password, array(
        \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
    ) );

    // Since MySQL supports it, don't automatically quote parameters to allow control over data types.
    // This comes in useful for automatically manipulating the LIMIT clause.
    $connection->setAttribute( \PDO::ATTR_EMULATE_PREPARES, false );

    // Uncomment to enable connection debugging.
    $connection->setAttribute( \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION );

    $this->set_mysql_global_defaults( $connection );
    return $connection;
}

When this function connects to a Remote AWS/RDS database, we configure it with a FQD for the $host variable. But, when running the same function locally, within our Docker setup, we must use the docker container name “jetpack_mysql” (as defined in the docker-compose.yml file) and not “127.0.0.1” or “localhost”.

Categories
Strava

Lunch Run

Ran 5.4 kilometers in 26 minutes.

Categories
Strava

Date night with Mattea

Cycled 1.3 kilometers in 14 minutes.

Categories
Strava

Friday Ride

Cycled 14.3 kilometers in 1 hours, 7 minutes.

Categories
Strava

Lunch Run

Ran 8.7 kilometers in 52 minutes.

Categories
Strava

Big Loop @PG

Cycled 19 kilometers in 1 hours, 15 minutes.

Categories
Strava

Lunch Run

Ran 8.3 kilometers in 43 minutes.