0

I want to run a php script using command line in Ubuntu (command: php /var/www/test.php), it runs ok in browser (url: http://example.com/test.php), but when running in command while pdo tried to connect to mysql, exception "could not find driver" was thrown, I checked the including paths everthing is correct, could somebody please help me about this?

code is very very simple:

<?php
$username = "root";
$pwd = "test";
try {
    $pdo = new PDO("mysql:host=localhost;port=3306;dbname=db", $username, $pwd, [PDO::ATTR_PERSISTENT => true]);
} catch (PDOException $e) {
    die("Connect Error Infomation:" . $e->getMessage());
}


Yancey
  • 3
  • 1
  • 5
  • CLI and Apache module usually have distinct php.inis – mario Oct 19 '20 at 10:27
  • Got. I found the php.ini for CLI, enabled "extension=pdo_mysql", now it threw a new exception: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20190902/pdo_mysql (/usr/lib/php/20190902/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pdo_mysql.so (/usr/lib/php/20190902/pdo_mysql.so: cannot open shared object file: No such file or directory)) – Yancey Oct 19 '20 at 11:00

0 Answers0