我刚刚安装了Debian Lenny与Apache, MySQL和PHP,我收到一个PDOException无法找到驱动程序。
这是它所引用的特定代码行:
$dbh = new PDO('mysql:host=')。DB_HOST。”;dbname = '。Db_name, db_user, db_pass)
DB_HOST、DB_NAME、DB_USER和DB_PASS是我已经定义的常量。它在生产服务器(以及我之前的Ubuntu server设置)上运行良好。
这与我的PHP安装有关吗?
在网上搜索也没有帮助,我得到的都是专家交流和例子,但没有解决方案。
我在我的Debian 6上修复了这个问题。
通常我只是安装了php5-common package。安装后,你必须重新启动你的web服务器(apache或nginx取决于你安装的哪个)。
然后我只是在apache进程id (lsof -p process_id)上做一个lsof,如下所示:
sudo lsof -p 1399 #replace 1399 by your apache process id
apache2 1399 root mem REG 254,2 80352 227236 /usr/lib/php5/20090626/xmlrpc.so
apache2 1399 root mem REG 254,2 166496 227235 /usr/lib/php5/20090626/suhosin.so
apache2 1399 root mem REG 254,2 31120 227233 /usr/lib/php5/20090626/pdo_mysql.so
apache2 1399 root mem REG 254,2 100776 227216 /usr/lib/php5/20090626/pdo.so
apache2 1399 root mem REG 254,2 135864 227232 /usr/lib/php5/20090626/mysqli.so
正如您在上面看到的,模块安装在一个不知道的文件路径上,或者由公共库路径引导:/usr/lib/php5/20090626/。对于您的安装,它可能不同,但只有pdo_mysql的路径。所以,pdo。所以,mysqli.so。所以,这就是为什么Drupal或其他php引擎找不到这个库,并显示错误:PDOException: could not find driver
我只是不知道为什么它被安装在这么奇怪的路径上,对我来说,这只是debian 6中库包安装脚本中的一个错误。
我通过为/usr/lib/php5/20090626/ to下的所有文件创建一个符号来解决这个问题
/usr/lib/php5/
在s /usr/lib/php5/20090626/* /usr/lib/php5/
对于使用MAMP的人,
如果你有
激活扩展= php_pdo_mysql.dll
设置你的扩展所在的正确路径,(例如:extension_dir = "C:\MAMP\bin\php\php7.4.1\ext\")
...你仍然不能在phpinfo()上看到pdo_mysql扩展,然后确保你从你的web服务器的文档根调用phpinfo(),而不是从其他地方。
如果你一直在其他地方调用它,那么你可能编辑了错误的php.ini文件:
Go to the document root of your web server (the path can be found in Mamp > preferences > Web server)
Create a file named info.php in this folder, open it and paste <?php phpinfo(); ?> then save the file.
Open the info.php you've just created in your browser (typically, http://localhost/info.php)
Now search for "Loaded Configuration File" in the page and look at the path of your php.ini file --> It's probably a different php.ini that the one you've been originally editing.
So open this file and make the edits (uncomment.., etc)
Restart your server
Check info.php again, the extension pdo_mysql should appear.
如果没有,如果你以前像我一样改变了你的服务器的文档根路径,我建议你重新设置为“C:\MAMP\htdocs”,并把你的网站放在这里,因为这真的解决了我的问题。
希望这能帮助到一些人。