我想在Ubuntu中使用命令行运行php脚本(命令:php /var/www/test.php),它在浏览器中正常运行(URL:http://example.com/test.php),但是在命令中运行时pdo尝试连接到mysql,抛出异常“找不到驱动程序”,我检查了所有路径是否正确,有人可以帮我吗?
代码非常简单:
<?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());
}