2

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); 
?>
sasi
  • 99
  • 1
  • 1
  • 11
  • can somebody help me? – sasi Sep 01 '14 at 16:21
  • usually 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? – cypherabe Sep 01 '14 at 16:33
  • post your config file – Richie Sep 01 '14 at 16:54

6 Answers6

4

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
Axel Amthor
  • 10,980
  • 1
  • 25
  • 44
  • afer 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? – sasi Sep 02 '14 at 06:28
  • Actually, the community will not debug your applications business logic. Anyway, this needs another new Question – Axel Amthor Sep 02 '14 at 06:42
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

0

This error usually occurs when some other app like skype and IIS are using ports of Apache i.e. 80 and mysql server i.e. 3306

You can eighter uninstall these apps or change port numbers of the localhost to something else and make correct changes in settings.php

Nikhil Goswami
  • 75
  • 2
  • 13
0

I suffered this error too. I did following things: 1. find out the port number used by mysql. In phpmyadmin, I ran the following sql:

show variables;

it shows a list of variables of mysql. scroll down, you will find port number.

  1. I edited the php code like this:

$dsn = 'mysql:host=127.0.0.1;port=3307; dbname=learnphpfast';

it worked like a charm!

KawaiKx
  • 9,558
  • 19
  • 72
  • 111
0

For Drupal Users -

This happens generally because of max_execution time for communicating server to mysql. Increase max execution time from 60 sec to upper limit you want and try refresh the page again.

It worked for me.

Avinash Thombre
  • 194
  • 1
  • 5
-1

Sasi, if your running this on a local server it may be your setup for windows the local server need to be configured to send email on.

Here you can find how to configure XAMPP to send mail from localhost.

Sorry that i answer you here, but i don't have enough reputation to make comments :D

Community
  • 1
  • 1
Supreme
  • 109
  • 7