php: SQLSTATE[HY000] [2002] 由于目标机器主动拒绝,无法建立连接 [英] php: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it
问题描述
我使用 php 创建了注册和登录表单.我从谷歌获取了源代码.
I have create register and login form using php. And i had took the source from google.
所以我在运行 index.php 时添加了所有相应的代码.
So i have added all the corresponding code, when run index.php.
显示,
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
我尝试使用 stackoverflow 和 google 解决此问题,但仍然无法纠正.
I tried for fixing this problem using stackoverflow and google, still can't to rectify.
我正在使用 xampp.在 xampp 控制面板中,apache 和 mysql 模块正在运行.和 apache 端口是 80,443 和 mysql 端口是 3306.
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.
提前致谢.
这是我的 config.php:
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);
?>
推荐答案
你不是说你的mysql端口是3306吗:
didn't you say your mysql port is 3306:
$db = new PDO("mysql:host=".DBHOST.";port=8889
//------------------------------------------^
这可能会有所帮助:
$db = new PDO("mysql:host=".DBHOST.";port=3306
这篇关于php: SQLSTATE[HY000] [2002] 由于目标机器主动拒绝,无法建立连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!