为什么无法连接到mysql?

DT

这是我的代码在Xampp的本地PC上可以正常工作:

$this->dbh = new PDO('mysql:host=localhost;dbname=dbdata', 'root','123456');
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

phi.ini:

;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_fileinfo.dll
;extension=php_ftp.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
;extension=php_exif.dll      ; Must be after mbstring as it depends on it
extension=php_mysqli.dll
;extension=php_oci8_12c.dll  ; Use with Oracle Database 12c Instant Client
;extension=php_odbc.dll
extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
;extension=php_shmop.dll

但是,当我将其上传到服务器时:使用win server 2012apache 2.4php 7.1,发生了给定的错误:

PDOException:PDO :: __ construct():PHP是在没有openssl扩展的情况下构建的,无法发送加密的密码

C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWDB.php:41堆栈跟踪:#0 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWDB.php(41):PDO-> __ construct('mysql :host = loca ...','root','123456')#1 C:\ Apache24 \ htdocs \ simsodep \ app \ model \ Home.php(21):ACWDB-> __ construct()#2 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWController.php(164):Home_model :: action_index()#3 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWController.php(32):ACWController-> dispach( )#4 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWCore.php(116):ACWController-> main(NULL)#5 C:\ Apache24 \ htdocs \ simsodep \ index.php(44):ACWCore: :acwork()#6 {main}下一个PDOException:SQLSTATE [HY000] [1045]在C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \中对用户'root'@'localhost'(使用密码:是)的访问被拒绝ACWDB.php:41堆栈跟踪:#0 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWDB.php(41):PDO-> __ construct('mysql:host = loca ...','root','123456')#1 C:\ Apache24 \ htdocs \ simsodep \ app \ model \ Home.php(21):ACWDB-> __ construct()#2 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWController.php(164):Home_model :: action_index()#3 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWController.php(32):ACWController-> dispach()#4 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWCore.php(116):ACWController- > main(NULL)#5 C:\ Apache24 \ htdocs \ simsodep \ index.php(44):ACWCore :: acwork()#6 {main}action_index()#3 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWController.php(32):ACWController-> dispach()#4 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWCore.php( 116):ACWController-> main(NULL)#5 C:\ Apache24 \ htdocs \ simsodep \ index.php(44):ACWCore :: acwork()#6 {main}action_index()#3 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWController.php(32):ACWController-> dispach()#4 C:\ Apache24 \ htdocs \ simsodep \ acwork \ class \ ACWCore.php( 116):ACWController-> main(NULL)#5 C:\ Apache24 \ htdocs \ simsodep \ index.php(44):ACWCore :: acwork()#6 {main}

为什么无法连接到mysql?

似乎您的php.ini中未启用openssl。首先打开php.ini文件

如果使用的是Linux,请找到extension = php_openssl.so并取消注释。

对于Windows,请找到extension = php_openssl.dll并取消注释。

还请确保添加使用PDO;如果没有的话,放在文件顶部。

祝好运!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么Ansible无法连接到MySql?

为什么Firefox无法连接到Facebook?

为什么我无法连接到无线?

docker-compose:为什么我的 webapp 无法连接到 mysql?

为什么Wordpress无法在此docker-compose应用中连接到MySQL?

为什么由于ERROR 2002无法连接到本地mysql服务器?

为什么spring-boot无法连接到本地mysql服务器?

为什么客户端无法连接到localhost:8080?

为什么UIScrollView委托无法连接到自身?

为什么我无法连接到Gremlin-Server?

为什么我无法连接到数据库?

为什么VirtualBox的访客无法连接到网络?

为什么我无法连接到此docker compose服务?

为什么psql无法连接到服务器?

PostgreSQL:为什么psql无法连接到服务器?

为什么Android Studio 无法连接到物理设备?

为什么我的 RestTemple 无法连接到服务器?

为什么我无法连接到AWS RDS?

为什么我无法连接到特定网站?

为什么我无法连接到Selenium Server?

为什么我无法连接到我的Linux实例?

为什么python代码无法远程连接到RabbitMQ?

为什么我无法在Docker中连接到Postgres?

为什么我无法连接到 docker 中的 postgres?

为什么我无法连接到我的 Atlas 集群?

为什么我无法连接到Ubuntu One?

为什么在phpmyadmin连接到mysql时出错?

如果我的应用未启用SSL,为什么在Azure中无法连接到MySQL服务器?

为什么我的 .NET Web API 应用程序在使用 docker-compose 时无法连接到 docker 上的 MySQL?