-1

I have an online database and I need to connect my local for some data synchronization purposes. so what I did was I setup an Remote MYSQL to the host using my local IP address. Now, have this line of code to connect to both local and online database:

$connection = mysql_connect('localhost', 'root');
if(!$connection) {
    die ("Database connection failed: " . mysql_error());
}


$db_select = mysql_select_db('db_name', $connection);
if(!$db_select) {
    die("Database connection failed: ". mysql_error());
}

/* connection to online database */
$connection_online = mysql_connect(localhost, DB_USER_ONLINE, DB_PASS_ONLINE);
if(!$connection_online) {
    die ("Database connection failed: " . mysql_error());
}


$db_select = mysql_select_db(DB_NAME_ONLINE, $connection_online);
if(!$db_select) {
    die("Database connection failed: ". mysql_error());
}

when I run this code I got this error: Warning: mysql_connect(): Access denied for user 'umalert_local'@'localhost' (using password: YES) in E:\xampp\htdocs\capstoneProjects\server_includes\connection.php on line 18 Database connection failed:

Am I doing a right thing? Is possible to connect to both local and online database in the same time? Thank you.

  • Silly question, but you changed "localhost" to the remote IP, right? – Jamie Taylor Dec 13 '13 at 08:39
  • 2
    don't use mysql firstly, use either PDO or MySQLi – Liam Sorsby Dec 13 '13 at 08:39
  • @ Janie Taylor: Yes, I've tried to change it but got this error too: Warning: mysql_connect(): The server requested authentication method unknown to the client [mysql_old_password] in E:\xampp\htdocs\capstoneProjects\server\_includes\connection.php on line 18 Warning: mysql_connect(): The server requested authentication method umknown to the client in E:\xampp\htdocs\capstoneProjects\server\_includes\connection.php on line 18 Database connection failed: – user3061819 Dec 13 '13 at 08:41
  • @Liam Sorsby: That's actually an old code of theirs. My task it just to make it sych the database. – user3061819 Dec 13 '13 at 08:43
  • 1
    Take a look at [this](http://stackoverflow.com/questions/14612551/mysql-remote-connection-fails-with-unknown-authentication-method) – Jamie Taylor Dec 13 '13 at 08:54
  • Please give code of line number 18. – Sonya Krishna Dec 13 '13 at 09:22

1 Answers1

-1

Try like this.

 $connection = mysql_connect('localhost', 'root','root');//if db password is root.In case of null leave it like ''
    if(!$connection) {
        die ("Database connection failed: " . mysql_error());
    }


    $db_select = mysql_select_db('db_name', $connection);
    if(!$db_select) {
        die("Database connection failed: ". mysql_error());
    }

    /* connection to online database */
    $connection_online = mysql_connect(localhost, DB_USER_ONLINE, DB_PASS_ONLINE);
    if(!$connection_online) {
        die ("Database connection failed: " . mysql_error());
    }


    $db_select = mysql_select_db(DB_NAME_ONLINE, $connection_online);
    if(!$db_select) {
        die("Database connection failed: ". mysql_error());
    }
Sonya Krishna
  • 269
  • 1
  • 11