PHP 7 RC3:如何安装缺少的 MySQL PDO

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32728860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:09:55  来源:igfitidea点击:

PHP 7 RC3: How to install missing MySQL PDO

phpmysqlubuntupdophp-7

提问by SmxCde

I am trying to setup webserver with PHP 7 RC3+ Nginxon Ubuntu 14.04(for test purposes).

我正在尝试使用PHP 7 RC3+ Nginxon设置网络服务器Ubuntu 14.04(用于测试目的)。

I installed Ubuntu in Vagrant using ubuntu/trusty64and PHP 7 RC 3 from Ond?ej Sury (https://launchpad.net/~ondrej/+archive/ubuntu/php-7.0).

我使用ubuntu/trusty64Ond?ej Sury ( https://launchpad.net/~ondrej/+archive/ubuntu/php-7.0) 的PHP 7 RC 3在 Vagrant 中安装了 Ubuntu 。

I can not find the way to install MySQL PDO(PHP sees PDOclass but not anything related to MySQL, like PDO::MYSQL_ATTR_DIRECT_QUERYetc.)

我找不到安装方式MySQL PDO(PHP 看到PDO类,但没有任何与 MySQL 相关的东西,例如PDO::MYSQL_ATTR_DIRECT_QUERY等)

Looks like there is no lib php7.0-mysql(by analogy with standard php5-mysqlndand php7.0-fpmetc. from Ond?ej)

貌似没有LIB php7.0-mysql(通过与标准类比php5-mysqlndphp7.0-fpm从OND等?EJ)

Section PDOin phpinfo():

PDOphpinfo()

PDO support      enabled
PDO drivers      no value

How can I get it?

我怎么才能得到它?

采纳答案by SmxCde

Since eggyaldidn't provided his comment as answer after he gave right advice in a comment - i am posting it here: In my case I had to install module php-mysql. See comments under the question for details.

由于eggyal在评论中给出了正确的建议后没有提供他的评论作为答案 - 我在这里发布:在我的情况下,我必须安装 module php-mysql。有关详细信息,请参阅问题下的评论。

回答by Angel115

For thoses running Linux with apache2 you need to install php-mysql

对于那些使用 apache2 运行 Linux 的用户,您需要安装 php-mysql

apt-get install php-mysql

or if you are running ubuntu 16.04 or higher just running the following command will be enought, no need to edit your php.ini file

或者如果您运行的是 ubuntu 16.04 或更高版本,只需运行以下命令即可,无需编辑 php.ini 文件

apt-get install php7.2-mysql


If you are running ubuntu 15.10 or below:

如果您运行的是 ubuntu 15.10 或更低版本:

Edit your php.inifile, it's located at /etc/php/[version]/apache2/php.iniand search for pdo_mysqlyou might found something like this

编辑你的php.ini文件,它位于/etc/php/[version]/apache2/php.ini并搜索pdo_mysql你可能会发现这样的东西

;extension=pdo_mysql.so

Change it to this

改成这个

extension=pdo_mysql.so

Save the file and restart apache

保存文件并重启apache

service apache2 restart

Check that it's available in your phpinfo()

检查它是否在您的phpinfo() 中可用

回答by StateLess

First install php-mysql

首先安装php-mysql

sudo apt-get install php7.0-mysql
//change the version number based on the php version

then enable the module

然后启用模块

sudo phpenmod pdo_mysql

and restart apache

并重新启动apache

sudo service apache2 restart 

回答by Jo?o Paulo Cercal

First, check if your php.ini has the extension enabled "php_pdo_mysql" and "php_mysqli" and the path of "extension_dir" is correct. If you need one of above configuration, then, you must restart the php-fpm to apply the changes.

首先,检查您的php.ini 是否启用了扩展名“php_pdo_mysql”和“php_mysqli”,并且“extension_dir”的路径是否正确。如果您需要上述配置之一,则必须重新启动 php-fpm 以应用更改。

In my case (where i am using the Windows OS in the company, i really prefer OSX or Linux), i solved the problem putting this values in the php.ini:

在我的情况下(我在公司使用 Windows 操作系统,我真的更喜欢 OSX 或 Linux),我解决了将这些值放在 php.ini 中的问题:

; ...

extension_dir = "ext"

; ... 

extension=php_mysqli.dll
extension=php_pdo_mysql.dll

; ...

I hope this helps.

我希望这有帮助。

回答by user1455180

If you are on windows, and your php folder is not in your PATH, you have set the absolute directory in your php.ini

如果您使用的是 Windows,并且您的 php 文件夹不在您的 PATH 中,则您已经在 php.ini 中设置了绝对目录

for example:

例如:

extension_dir = "C:/php7/ext"

and uncomment

并取消注释

extension=php_mysqli.dll
extension=php_pdo_mysql.dll

Restart apache2.4 and it should work.

重新启动 apache2.4,它应该可以工作了。

I hope it helps.

我希望它有帮助。

回答by micl

  1. download the source code of php 7 and extract it.
  2. open your terminal
  3. swim to the ext/mysqli directory
  4. use commands:

    phpize

    ./configure

    make

    make install (as root)

  5. enable extension=mysqli.so in your php.ini file
  6. done!
  1. 下载php 7的源代码并解压。
  2. 打开你的终端
  3. 游到 ext/mysqli 目录
  4. 使用命令:

    phpize

    。/配置

    制作

    进行安装(以 root 身份)

  5. 在 php.ini 文件中启用 extension=mysqli.so
  6. 完毕!

This worked for me

这对我有用

回答by jgadrow

I had, pretty much, the same problem. I was able to see that PDO was enabled but I had no available drivers (using PHP 7-RC4). I managed to resolve the issue by adding the php_pdo_mysql extension to those which were enabled.

我有,几乎,同样的问题。我能够看到 PDO 已启用,但我没有可用的驱动程序(使用 PHP 7-RC4)。我设法通过将 php_pdo_mysql 扩展添加到已启用的扩展来解决该问题。

Hope this helps!

希望这可以帮助!

回答by Xorifelse

Had the same issue, resolved by actually enabling the extension in the php.ini with the right file name. It was listed as php_pdo_mysql.so but the module name in /lib/php/modules was called just pdo_mysql.so

有同样的问题,通过在 php.ini 中使用正确的文件名实际启用扩展来解决。它被列为 php_pdo_mysql.so 但 /lib/php/modules 中的模块名称被称为 pdo_mysql.so

So just remove the "php_" prefix from the php.ini file and then restart the httpd service and it worked like a charm.

所以只需从 php.ini 文件中删除“php_”前缀,然后重新启动 httpd 服务,它就像一个魅力。

Please note that I'm using Arch and thus path names and services may be different depending on your distrubution.

请注意,我使用的是 Arch,因此路径名称和服务可能会根据您的发行版而有所不同。

回答by user3912517

I'll start with the answer then context NOTE this fix was logged above, I'm just re-stating it for anyone googling.

我将从答案开始,然后是上下文 注意此修复程序已记录在上面,我只是为任何使用谷歌搜索的人重新说明它。

  1. Download the source code of php 7 and extract it.
  2. open your terminal
  3. swim to the ext/pdo_mysql directory
  4. use commands:

    phpize

    ./configure

    make

    make install (as root)

  5. enable extension=mysqli.so in your php.ini file

  1. 下载php 7的源代码并解压。
  2. 打开你的终端
  3. 游到 ext/pdo_mysql 目录
  4. 使用命令:

    phpize

    。/配置

    制作

    进行安装(以 root 身份)

  5. 在 php.ini 文件中启用 extension=mysqli.so

This is logged as an answer from here (please upvote it if it helped you too): https://stackoverflow.com/a/39277373/3912517

这被记录为这里的答案(如果对您有帮助,请点赞):https: //stackoverflow.com/a/39277373/3912517

Context: I'm trying to add LimeSurvey to the standard WordPress Docker. The single point holding me back is "PHP PDO driver library" which is "None found"

上下文:我正在尝试将 LimeSurvey 添加到标准的 WordPress Docker。阻碍我的一点是“PHP PDO 驱动程序库”,即“未找到”

php -i | grep PDO                                                                                  
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_odbc' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  Module 'mysqli' already loaded in Unknown on line 0
PDO
PDO support => enabled
PDO drivers => sqlite
PDO Driver for SQLite 3.x => enabled

Ubuntu 16 (Ubuntu 7.3.0)

Ubuntu 16 (Ubuntu 7.3.0)

apt-get install php7.0-mysql

Result:

结果:

Package 'php7.0-mysql' has no installation candidate

Get instructions saying all I have to do is run this:

获取说明我所要做的就是运行这个:

add-apt-repository -y ppa:ondrej/apache2

But then I get this:

但后来我得到了这个:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 223: ordinal not in range(128)

So I try and force some type of UTF: LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/apache2 and I get this: no valid OpenPGP data found.

所以我尝试强制使用某种类型的 UTF: LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/apache2 我得到这个:没有找到有效的 OpenPGP 数据。

Follow some other instructions to run this: apt-get update and I get this: Err:14 http://ppa.launchpad.net/ondrej/apache2/ubuntucosmic/main amd64 Packages 404 Not Found Err:15 http://ppa.launchpad.net/ondrej/php/ubuntucosmic/main amd64 Packages 404 Not Found and - I think because of that - I then get:

按照其他一些说明运行它:apt-get update,我得到这个:Err:14 http://ppa.launchpad.net/ondrej/apache2/ubuntucosmic/main amd64 Packages 404 Not Found Err:15 http:// ppa.launchpad.net/ondrej/php/ubuntucosmic/main amd64 Packages 404 Not Found 并且 - 我想正因为如此 - 我然后得到:

The repository 'http://ppa.launchpad.net/ondrej/apache2/ubuntu cosmic Release' does not have a Release file.

By this stage, I'm still getting this on apt-get update:

到了这个阶段,我仍然在 apt-get update 上得到这个:

Package 'php7.0-mysql' has no installation candidate.

I start trying to add in php libraries, got Unicode issues, tried to get around that and.... you get the idea... whack-a-mole. I gave up and looked to see if I could compile it and I found the answer I started with.

我开始尝试添加 php 库,遇到了 Unicode 问题,试图解决这个问题……你明白了……打地鼠。我放弃了,看看我是否可以编译它,我找到了我开始的答案。

You might be wondering why I wrote so much? So that anyone googling can find this solution (including me!).

你可能想知道为什么我写了这么多?这样任何使用谷歌搜索的人都可以找到这个解决方案(包括我!)。

回答by Dhanush-uc

['class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost:3306;dbname=testdb',
    'username' => 'user',
    'password' => 'password',
    'charset' => 'utf8',]

It's simple: Just provide the port number along with the host name and set default sock path to your mysql.sockfile path in php.iniwhich the server is running on.

很简单:只需提供端口号和主机名,并将默认 sock 路径设置为运行服务器的mysql.sock文件路径php.ini