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...

4

2 回答 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..

于 2014-03-08T11:23:10.523 回答
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.

于 2014-02-25T16:17:58.563 回答