更新时间:2023-02-23 16:36:50
找出您实际需要的PDO驱动程序(MySQL,MS SQL ...?)
Find out which PDO driver you actually need (MySQL, MS SQL...?)
通过自己实例化PDO进行测试,以避免发生其他错误:
Test by instantiating PDO yourself, to avoid errors elsewhere:
$db = new PDO('mysql:host=127.0.0.1;dbname=testdb', 'username', 'password');
如果您仍然得到找不到驱动程序",现在可以确定自己确实缺少它:)
If you still get "could not find driver", now you can be sure that you're really missing it :)
如何安装(如果您还没有安装的话)在很大程度上取决于您的系统.例如,在Debian Linux上,您需要执行apt-get install php5-mysql
,它会安装mysql
,mysqli
和pdo_mysql
扩展名.
How to install it, if you don't have it already, depends a lot on your system. On Debian Linux, for example, you need to do apt-get install php5-mysql
, which installs mysql
, mysqli
and pdo_mysql
extensions.
安装后,请确保已在php.ini
中启用它.确保您正在编辑正确文件-网络服务器使用的文件.
After you install it, ensure that it's enabled in php.ini
. make sure that you're editing the correct file - the one that is used by your webserver.
然后,要验证扩展程序是否正确加载,请执行以下任一操作:
Afterwards, to verify the extension was loaded correctly, either:
创建一个执行phpinfo()
的脚本.您应该看到一个 PDO 部分,其中包含键 PDO驱动程序和一个值,例如"mysql, pgsql
"或
create a script which executes phpinfo()
. You should see a PDO section with a key PDO drivers and a value such as "mysql, pgsql
", or
从命令行运行php -m
,您应该会看到例如pdo_mysql
.
run php -m
from the command line and you should see pdo_mysql
for example.