1

I just created an android app in which app is connected with MySql through PHP files.. I did according to this tutorial this

But I am able to connect when igave localhost address when i gave my server address it is not working .. The following is db_connect .. i didnt make any change

  <?php

/**
 * A class file to connect to database
 */
class DB_CONNECT {

    // constructor
    function __construct() {
        // connecting to database
        $this->connect();
    }

    // destructor
    function __destruct() {
        // closing db connection
        $this->close();
    }

    /**
     * Function to connect with database
     */
    function connect() {
        // import database connection variables
        require_once __DIR__ . '/db_config.php';

        // Connecting to mysql database
        $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());

        // Selecing database
        $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());

        // returing connection cursor
        return $con;
    }

    /**
     * Function to close db connection
     */
    function close() {
        // closing db connection
        mysql_close();
    }
}

?>

db_config.php

<?php

/*
 * All database connection variables
 */

define('DB_USER', "root");


 // db user
define('DB_PASSWORD', "");

 // db password (mention your db password here)
define('DB_DATABASE', "androidhive");

 // database name
define('DB_SERVER', "localhost"); // db server


?>

this is the link i uploaded my file...

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/96/11645896/html/app/db_connect.php on line 28 Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Warning: mysql_close(): no MySQL-Link resource supplied in /home/content/96/11645896/html/app/db_connect.php on line 42

but message came like this... what I have to do...

2
  • Do you have mysqld running? Commented Oct 25, 2013 at 12:27
  • how we will know that..? Commented Oct 25, 2013 at 13:02

2 Answers 2

1

You need to give a server address of your own.. Instead of androidhive's and give the username and password of that particular server.. and edit the db_config.php file according to that.. then try to connect..

Sign up to request clarification or add additional context in comments.

Comments

0

Check your db credentials and make sure mysqld is running. Try this /etc/init.d/mysql status or http://www.cyberciti.biz/faq/how-to-find-out-if-mysql-is-running-on-linux/ to know if MySQL is up.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.