Click here to Skip to main content
15,881,709 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:

C#
<?php

define("DB_HOST","localhost:81");
define("DB_USER","root");
define("DB_PASSWORD,"sandeep");
define("DB_DATABASE","android_api");

?>




DB_Connect file:
<?php
 
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
        mysql_select_db(DB_DATABASE);
 
        // return database handler
        return $con;
    }
 
    // Closing database connection
    public function close() {
        mysql_close();
    }
 
}
 
?>
Posted
Comments
ChauhanAjay 22-Aug-14 6:27am    
Try changing the local host to 127.0.0.1


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?

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