PHP:SQLSTATE [HY000]无连接可以作出[2002]由于目标机器积极拒绝, [英] php: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it
问题描述
我已创建使用PHP注册和登录表单。而我从谷歌采取了来源。
所以,我添加了所有相应的code,运行时的index.php。
这表明,
SQLSTATE [HY000]无连接可以作出[2002]由于目标机器积极地拒绝它。
我试着使用计算器和谷歌解决这个问题,仍然无法纠正。
我使用的XAMPP。在XAMPP控制面板,Apache和MySQL模块运行。和apache端口 80,443 和mysql端口为 3306
可我知道,其他任何我的错误?..
有人能帮助我吗?任何帮助将是AP preciated。
先谢谢了。
这是我的config.php:
< PHP
ob_start();
在session_start();//设置时区
date_default_timezone_set(欧洲/伦敦);//数据库凭据
定义('DBHOST','localhost'的);
定义('DBUSER','根');
定义('DBPASS','');
定义('DBNAME','注册');//申请地址
定义('DIR','HTTP://domain.com/');
定义('SITEEMAIL','noreply@domain.com');尝试{ //创建PDO连接
$ DB =新PDO(MySQL的:主机=DBHOST;港口= 8889;数据库名=DBNAME,DBUSER,DBPASS。);
$ DB-GT&;的setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION);}赶上(PDOException $ E){
//显示错误
呼应'< p =类BG-危险>'。$ E->的getMessage()。'< / P>';
出口;
}//包括用户类,传入数据库连接
包括(类/ user.php的');
$用户=新用户($分贝);
?>
你不是说你的mysql端口为3306:
$ DB =新PDO(MySQL的:主机=DBHOST;港口= 8889。
// ------------------------------------------ ^
这可能帮助:
$ DB =新PDO(MySQL的:主机=DBHOST;港口= 3306。
I have create register and login form using php. And i had took the source from google.
So i have added all the corresponding code, when run index.php.
It shows,
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
I tried for fixing this problem using stackoverflow and google, still can't to rectify.
I Am using xampp. In xampp control panel, apache and mysql modules are running. and apache port is 80,443 and mysql port is 3306.
May i know, any other my mistake?..
Can someone help me? Any help would be appreciated.
Thanks in advance.
This is my config.php:
<?php
ob_start();
session_start();
//set timezone
date_default_timezone_set('Europe/London');
//database credentials
define('DBHOST','localhost');
define('DBUSER','root');
define('DBPASS','');
define('DBNAME','register');
//application address
define('DIR','http://domain.com/');
define('SITEEMAIL','noreply@domain.com');
try {
//create PDO connection
$db = new PDO("mysql:host=".DBHOST.";port=8889;dbname=".DBNAME, DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
//show error
echo '<p class="bg-danger">'.$e->getMessage().'</p>';
exit;
}
//include the user class, pass in the database connection
include('classes/user.php');
$user = new User($db);
?>
didn't you say your mysql port is 3306:
$db = new PDO("mysql:host=".DBHOST.";port=8889
//------------------------------------------^
this might help:
$db = new PDO("mysql:host=".DBHOST.";port=3306
这篇关于PHP:SQLSTATE [HY000]无连接可以作出[2002]由于目标机器积极拒绝,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!