Click here to Skip to main content
15,068,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to connect MySQL database via PHP Script but nothing is happening the conncetion Successful message is not printing at all, my code for connection is follows:

config.php file:




DB_Connect file:
class DB_Connect {
    // constructor
    function __construct() {
    // destructor
    function __destruct() {
        // $this->close();
    // Connecting to database
    public function connect() {
        require_once 'config.php';
        // connecting to mysql
        $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
        // selecting database
        // return database handler
        return $con;
    // Closing database connection
    public function close() {
ChauhanAjay 22-Aug-14 6:27am
Try changing the local host to

Is your my sql installed with default port a 81.
Sandeep Londhe 22-Aug-14 6:34am
no actually at first it is not opening so i changed the port from 80 to 81 then it starts but the php code is not returning anything
ChauhanAjay 22-Aug-14 6:44am
In case you are providing the port number it should be of mysql.
Sandeep Londhe 22-Aug-14 6:47am
Yes It Simpley Says Access Denied When i am trying to run the PHP script
vbmike 22-Aug-14 10:07am
If you have mysql installed on your local development machine, when you use mysql_connect statement you need three things, the host, the user, the pwd. You have those in your code. I have not had to specify a port as mysql will specify that for you usually. Try removing the port from the definition of DB_HOST. Mysql service must be running when you try this script as you know so I assume you have mysql installed on your development machine. In addition you are using some thing similar to webmatrix or Apache server for the host?
W Balboos, GHB 22-Aug-14 11:35am
Minor Point: Your missing a quote after DB_PASSWORD on your first block, third line.

This may well cause your password to fail and then Access Denied.
Arun-23 25-Aug-14 0:11am
yeah check it out define("DB_PASSWORD,"sandeep"); to define("DB_PASSWORD","sandeep");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900