PHP built-in webserver cannot find PDO

21 hours ago 2
ARTICLE AD BOX

I run php -S 127.0.0.1:8000 on my computer and open in the browser my.php with the following content:

<?php $pdo = new PDO("..."); $sql = "SELECT 'Hello, World!\n' AS message"; $stmt = $pdo->query($sql); $result = $stmt->fetch(PDO::FETCH_ASSOC); echo $result['message']; ?>

Then I get an exception

"Fatal error: Uncaught Error: Class 'PDO' not found"

However, the class PDO is found without any problems when I run in shell the command php my.php.

It is totally unclear to me why the code which works fine in the shell does not work for the built-in server. Any hints would be welcome!

From phpinfo() I see "--disable-pdo" in Configure Command. But php -m outputs, in particular, PDO, pdo_sqlite, pdo_pgsql and other modules. And in any case, everything works in the command line, so the issue seems to be in the built-in webserver.

vimuth's user avatar

vimuth

5,89157 gold badges100 silver badges128 bronze badges

Skeeve's user avatar

6

Read Entire Article