WordPress / playground-tools

GNU General Public License v2.0
127 stars 38 forks source link

WordPress crashes when connecting to MySQL #237

Open adamziel opened 2 months ago

adamziel commented 2 months ago

@zzap's VS Code extension crashed when running a MySQL-connected WordPress. We've narrowed it down to the reproduction case below. It's probably also present in wp-now and Studio – CC @sejas @kozer @wojtekn. It's most likely Asyncify-related, here's a doc page on how to debug and fix those: https://wordpress.github.io/wordpress-playground/architecture/wasm-asyncify Even posting a stack trace here would go a long way.

<?php

$servername = "127.0.0.1";
$username = "username";
$password = "password";
$dbname = "myDb";

// Initialize mysqli instance
$mysqli = mysqli_init();

if (!$mysqli) {
    die('mysqli_init failed');
}

// Establish connection
if (!mysqli_real_connect($mysqli, $servername, $username, $password, $dbname)) {
    die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
echo 'Success... ' . $mysqli->host_info . "\n";

$mysqli->close();
zzap commented 2 months ago

Let me know if there's any additional info you need from me.

wojtekn commented 2 months ago

@adamziel I've just tried that on my local in Studio and I couldn't reproduce it.

  1. Start database server:
    docker run --name studio-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d circleci/mariadb:10.3.23
  2. Add and start site in Studio
  3. Open wp-config.php
  4. Replace the content with the following:
    
    <?php
    $servername = "127.0.0.1";
    $username = "root";
    $password = "my-secret-pw";
    $dbname = "circle_test";

// Initialize mysqli instance $mysqli = mysqli_init();

if (!$mysqli) { die('mysqli_init failed'); }

// Establish connection if (!mysqli_real_connect($mysqli, $servername, $username, $password, $dbname)) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } echo 'Success... ' . $mysqli->host_info . "\n";

$mysqli->close(); die;;

6. Refresh page and notice:

Success... 127.0.0.1 via TCP/IP

adamziel commented 2 months ago

Interesting! @zzap, what's your mysql version? Also @wojtekn would you also try vs code?

zzap commented 2 months ago

mysql Ver 8.0.36-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))

wojtekn commented 2 months ago

@adamziel it works well for me in Visual Studio Code, too:

Screenshot 2024-04-26 at 12 11 01