php: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it
18,842
Solution 1
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
Solution 2
$db = new PDO("mysql:host=".DBHOST.";port=3306;dbname=".DBNAME, DBUSER, DBPASS);
you should change the port number to default: 3306! hope this helps
Comments
-
sasi almost 2 years
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','[email protected]'); 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); ?>
-
sasi over 9 yearscan somebody help me?
-
cypherabe over 9 yearsusually this error means that something is blocking the request. as apache and mysql are running on the same machine, a firewall is unlikely. you should check the connection parameter in the copied code: are the functions fitting for mysql? is 'localhost' or '127.0.0.1' used as host? (try switching the host parameter) is there a different port specified?
-
Richie over 9 yearspost your config file
-
-
sasi over 9 yearsafer corrected error, there is display register page, after finished registration, didn't receive email confirmation in my mail, in localhost is not possible right? But i need every user after registerration completed, it should send confirmation mail for corresponding users, for that what i do. can you guide me please?
-
Axel Amthor over 9 yearsActually, the community will not debug your applications business logic. Anyway, this needs another new Question