Editor 2.0.7 with PHP 7.3.27 versus PHP 8.1.7

Editor 2.0.7 with PHP 7.3.27 versus PHP 8.1.7

rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
edited July 2022 in Editor

I am currently migrating my server to the latest version of PHP. I use Editor 2.0.7 in both environments.
With PHP 7.3.27 Editor returns all values as strings. Like in here:

With PHP 8.1.7 numeric values are returned as numbers. Like in here:

This new behavior is not what I want. In fact it makes my Javascript crash. "replace" doesn't work on a number for example etc..

How can I turn this new behavior off?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
    edited July 2022

    After searching the web I found out that this is something that PHP 8.1 is doing unfortunately. The solution is obviously to tell PDO not to do this.

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     * Database user / pass
     */
    $sql_details = array(
        "type" => "Mysql",     // Database type: "Mysql", "Postgres", "Sqlserver", "Sqlite" or "Oracle"
        "user" => "yourUserName",          // Database user name
        "pass" => "yourPW",          // Database password
        "host" => "localhost", // Database host
        "port" => "",          // Database connection port (can be left empty for default)
        "db"   => "yourDBName",          // Database name
        "dsn"  => "charset=utf8mb4",          // PHP DSN extra information. Set as `charset=utf8mb4` if you are using MySQL
        "pdoAttr" => array()   // PHP PDO attributes array. See the PHP documentation for all options
    );
    

    I don't understand how I can provide an array of PDO attributes. I read how to set a single attribute, but not how to set an array. The attribute and its value are separated by a comma. How do you push this into an array?

    Basically I need to do this:

    ...
    $db->resource()->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true );
    

    ... but that doesn't provide an array?!

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
    edited July 2022

    ok, this does the trick. And of course you need to provide an associative array for the attributes... Problem solved.

    $sql_details = array(
        "type" => "Mysql",     // Database type: "Mysql", "Postgres", "Sqlserver", "Sqlite" or "Oracle"
        "user" => "yourUserName",          // Database user name
        "pass" => "yourPW",          // Database password
        "host" => "localhost", // Database host
        "port" => "",          // Database connection port (can be left empty for default)
        "db"   => "yourDBName",          // Database name
        "dsn"  => "charset=utf8mb4",          // PHP DSN extra information. Set as `charset=utf8mb4` if you are using MySQL
        "pdoAttr" => array( PDO::ATTR_STRINGIFY_FETCHES => true )   // PHP PDO attributes array. See the PHP documentation for all options
    );
    
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Hi Roland,

    I wasn't aware of that change in PHP8 either. I can see upsides and downsides!

    Thanks for posting your findings :)

    Allan

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
    edited July 2022

    Hi Allan,

    yes, it was harder than usual to find the solution. I found it here:
    https://github.com/doctrine/dbal/issues/5228

    This doesn't apply to PHP 8.0, only 8.1 and higher.

    Roland

    P.S.: Maybe one other thing to share. I also migrated from MySQL 5.7.33 to MariaDB 10.6.8 which is pretty much the latest stable release compatible with the latest version of Plesk Obsidian. My new virtual linux server might be a little stronger than the old one but not much. One query loading all my users took 18 seconds previously; this is now down to 1.3 seconds without any further changes. This is pretty awesome I think. (I also updated from Ubuntu 16.04 to Ubuntu 20.04 - not sure whether that does something, too.).

Sign In or Register to comment.