mysqli :: real_connect():(HY000/2002):实时连接被拒绝 [英] mysqli::real_connect(): (HY000/2002): Connection refused on Live
问题描述
我使用PHP,Mysql和Codeignater版本3创建一个网站.然后将其托管在iPage上.当我实时上传时,我会在配置文件中进行更改.
I create a web site using PHP, Mysql, and Codeignater version 3. Then host it on iPage. When I upload on live I make changes in config file.
$db['default'] = array(
'dsn' => '',
'hostname' => '66.96.147.118',
'username' => 'bit_root',
'password' => 'root',
'database' => 'bit_shilp',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
我使用codeignater版本3.在本地,效果很好.但是在实时网站上却给出了错误.
I use codeignater version 3. On local it work great. But on live site It gives an error.
请参见此链接 http://bitshilp.com/BitShilp/index.php/home
它给出了这样的错误:
遇到PHP错误
A PHP Error was encountered
严重性:警告
消息:mysqli :: real_connect():(HY000/2002):连接被拒绝
Message: mysqli::real_connect(): (HY000/2002): Connection refused
文件名:mysqli/mysqli_driver.php
Filename: mysqli/mysqli_driver.php
行号:161
回溯:
文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php 行:7 功能:__ construct
File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php Line: 7 Function: __construct
文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php 线:292 函数:require_once 遇到PHP错误
File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php Line: 292 Function: require_once A PHP Error was encountered
严重性:警告
消息:无法修改标头信息-已发送的标头(输出始于 /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/system/core/Exceptions.php:272)
Message: Cannot modify header information - headers already sent by (output started at /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/system/core/Exceptions.php:272)
文件名:core/Common.php
Filename: core/Common.php
行号:568
回溯:
文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php 行:7 功能:__ construct
File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php Line: 7 Function: __construct
文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php 线:292 功能:require_once
File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php Line: 292 Function: require_once
谢谢.
推荐答案
我使用AWS RDS MySQL发生了同样的问题.看了各种资料,但截至本主题为止,几乎都没有答案. 虽然此答案对我有帮助,但请记住要在服务器上更新主机名.访问您的SSH并按照以下步骤操作:
Same problem occurd with me, with AWS RDS MySQL. Looked various sources, but as of this thread, almost all lack of answer. While this answer helped me, tweak in mind to update hostnames at server. Access your SSH and follow the steps:
cd /etc/
sudo nano hosts
现在,在此处添加您的主机名:例如:
127.0.0.1 localhost
127.0.0.1 subdomain.domain.com [if cname redirected to endpoints]
127.0.0.1 xxxxxxxx.xxxx.xxxxx.rds.amazonaws.com [Endpoints]
现在,按如下所示配置config/database.php
:
and now, configuring config/database.php
as follows:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '35.150.12.345',
'username' => 'user-name-here',
'password' => 'password-here',
'database' => 'database-name-here',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
其中35.150.12.345
是您的 IPv4公共IP ,位于其中的ec2-dashboard > Network Interfaces > Description : RDSNetworkInterface >> IPv4 Public
IP('35 .150.12.345').
where 35.150.12.345
is your IPv4 Public IP, located at ec2-dashboard > Network Interfaces > Description : RDSNetworkInterface >> IPv4 Public
IP('35.150.12.345') there.
注意:请注意,只有IPV4可以在主机名"选项下使用.主机名,cname,域将输出数据库连接错误.
这篇关于mysqli :: real_connect():(HY000/2002):实时连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!