简体   繁体   English

PDO连接到远程MySQL数据库

[英]PDO connecting to remote MySQL db

I'm trying to connect to a remote MySQL db using PHP. 我正在尝试使用PHP连接到远程MySQL数据库。 It was supposed to be an easy task but cause I'm a newbie in PHP it's going bad. 这本来应该是一件容易的事,但由于我是PHP的新手,所以情况越来越糟。 I got a key-cert.pem, a client-cert.pem, host name and credentials. 我得到了一个key-cert.pem,一个client-cert.pem,主机名和凭据。 I copy one of the examples around the web and this is what I did: 我在网上复制了一个示例,这就是我所做的:

pdoDb = new PDO(
  'mysql:host=customer_host_name;dbname=customer_db_name', 
  'my_username', 
  'my_password', 
  array(
    PDO::MYSQL_ATTR_SSL_KEY=>'C:/Apache24/htdocs/PETALO/lib/client-key.pem',
    PDO::MYSQL_ATTR_SSL_CERT=>'C:/Apache24/htdocs/PETALO/lib/client-cert.pem'
  ));

When I execute this code I got this error back: 当我执行这段代码时,我得到了这个错误:

Warning: PDO::__construct(): this stream does not support SSL/crypto in C:\Apache24\htdocs\custo\lib\database.php on line 16

Warning: PDO::__construct(): Cannot connect to MySQL by using SSL in C:\Apache24\htdocs\custo\lib\database.php on line 16

Warning: PDO::__construct(): [2002] (trying to connect via tcp://customer_host_name:3306) in C:\Apache24\htdocs\custo\lib\database.php on line 16
error: SQLSTATE[HY000] [2002]

Customer doesn't give me a ca-cert.pem and credentials are correct. 客户没有给我ca-cert.pem并且凭据正确。 What am I missing? 我想念什么?

The warning has nothing to do with any of the certificate files. 该警告与任何证书文件无关。 Either OpenSSL is not enabled in the php.ini configuration file, or your php version was not compiled with SSL support at all, or the mysql driver / php you use has a bug, like php bug #55870 . 要么在php.ini配置文件中未启用OpenSSL,要么您的php版本根本没有使用SSL支持进行编译,或者您使用的mysql驱动程序/ php有一个bug,例如php bug#55870 Certificates and mysql settings will only come into play after PDO tries to initiate a connection over SSL. 证书和mysql设置仅在PDO尝试通过SSL发起连接后才起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM