PDO missing from DevKinsta php, when using Propel

Hello there, I’m trying to use Propel in my system, and though my credentials for my DB seem correct, the PHP installation seems to be missing PDO entirely. Does anyone have insight into why or what is it I’m encountering? The full stack trace is below:

[12-Apr-2023 16:29:44 UTC] PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [2002] Connection refused in /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/connection/PropelPDO.php:152
Stack trace:
#0 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/connection/PropelPDO.php(152): PDO->__construct()
#1 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/Propel.php(686): PropelPDO->__construct()
#2 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/Propel.php(586): Propel::initConnection()
#3 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/Propel.php(561): Propel::getMasterConnection()
#4 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/classes/security-service.php(485): Propel::getConnection()
#5 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/classes/security-service.php(473): SecurityService->create_pdo_adapter()
#6 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/classes/security-service.php(29): SecurityService->connect()
#7 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/public/class-l4g-public.php(112): SecurityService->__construct()
#8 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/includes/class-l4g.php(196): L4g_Public->__construct()
#9 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/includes/class-l4g.php(80): L4g->define_public_hooks()
#10 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/l4g.php(78): L4g->__construct()
#11 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/l4g.php(82): run_l4g()
#12 /www/kinsta/public/l4g-stage/wp-settings.php(453): include_once('...')
#13 /www/kinsta/public/l4g-stage/wp-config.php(118): require_once('...')
#14 /www/kinsta/public/l4g-stage/wp-load.php(50): require_once('...')
#15 /www/kinsta/public/l4g-stage/wp-blog-header.php(13): require_once('...')
#16 /www/kinsta/public/l4g-stage/index.php(17): require('...')
#17 {main}

Next PropelException: Unable to open PDO connection [wrapped: SQLSTATE[HY000] [2002] Connection refused] in /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/Propel.php:691
Stack trace:
#0 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/Propel.php(586): Propel::initConnection()
#1 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/Propel.php(561): Propel::getMasterConnection()
#2 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/classes/security-service.php(485): Propel::getConnection()
#3 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/classes/security-service.php(473): SecurityService->create_pdo_adapter()
#4 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/classes/security-service.php(29): SecurityService->connect()
#5 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/public/class-l4g-public.php(112): SecurityService->__construct()
#6 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/includes/class-l4g.php(196): L4g_Public->__construct()
#7 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/includes/class-l4g.php(80): L4g->define_public_hooks()
#8 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/l4g.php(78): L4g->__construct()
#9 /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/l4g.php(82): run_l4g()
#10 /www/kinsta/public/l4g-stage/wp-settings.php(453): include_once('...')
#11 /www/kinsta/public/l4g-stage/wp-config.php(118): require_once('...')
#12 /www/kinsta/public/l4g-stage/wp-load.php(50): require_once('...')
#13 /www/kinsta/public/l4g-stage/wp-blog-header.php(13): require_once('...')
#14 /www/kinsta/public/l4g-stage/index.php(17): require('...')
#15 {main}
  thrown in /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/Propel.php on line 691```

You can see a few lines above that the DB connection info appears to be correct:
```[12-Apr-2023 16:29:44 UTC] PHP  16. Propel::initConnection($conparams = ['dsn' => 'mysql:host=127.0.0.1;dbname=L4G_Stage', 'user' => 'root', 'password' => 'eiUpaJVtKZx1788J'], $name = 'l4g', $defaultClass = *uninitialized*) /www/kinsta/public/l4g-stage/wp-content/plugins/l4g/vendor/dayspring-tech/propel1/runtime/lib/Propel.php:586

Matching my DevKinsta:

I dumped a phpinfo() and I see this:

Can anyone help?

Hi @alee

It looks like you’re getting a “Connection refused” error. Is the devkinsta_db Docker container running? If so, can you restart that container? Perhaps even shut down/exit DevKinsta, restart Docker, then start DevKinsta again, does it work?

If that doesn’t work, can you try setting DB_HOST to localhost in wp-config.php ?

It seems PHP is running with PDO support per your screenshot. If nothing else, does the “Open database manager” tool work for this Site?

Best regards,
Zach

@alee I had a similar problem migrating a stand-alone PHP app using PHP to test with Kinsta. The connection string fails with the host set to ‘localhost’ or ‘127.0.0.1’ and the port specified.
My solution is to use host devkinsta_db so there is no need for the port to be specified.

Simple example:-

   $host   = 'devkinsta_db';
    $dbname = 'tonygirling';
    $user   = 'root';
    $pass   = 'db-password-here';

    $connection = 'mysql:dbname=' . $dbname . ';host=' . $host;
    $pdo        = new PDO( $connection, $user, $pass );

    $stmt = $pdo->query( 'SELECT * FROM users' );

    while ( $row = $stmt->fetch() ) {
        echo $row['name'] . "\n";
    }

Hope this helps.

1 Like

Hello @Tony_Girling and welcome to DevKinsta Community!
Thank you very much for sharing your solution, I am sure it can be helpful in a few scenarios :+1:

Regards,
Alessandro