[SOLVED] Trouble connecting to a remote mysql db

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
scottz
Forum Newbie
Posts: 3
Joined: Fri Apr 15, 2005 11:04 am

[SOLVED] Trouble connecting to a remote mysql db

Post by scottz »

I'm running php and tomcat on my personal machine and trying to connect to a database on a different server. phpMyAdmin is running on my personal machine and is able to successfully update databases/tables/records, etc. on the database server.

My php code, however, fails to connect to the database server. I've tried the following:

Code: Select all

<?php
$hostname1 = "10.3.1.27:3306";
$hostname2 = "10.3.1.27";
$hostname3 = "marcian.stthom.edu:3306";
$hostname4 = "marcian.stthom.edu";
$username = "root";
$passWord = "XXXXXXXX";
$dataBase = "test";
$conn = mysql_connect($hostName4,$userName,$passWord) or die ("Failed to connect to server");
mysql_select_db($dataBase,$conn) or die("Failed to select database!");
?>
and

Code: Select all

<?php
$hostname = "marcian.stthom.edu";
$username = "root";
$passWord = "XXXXXXX";
$dataBase = "test";
$query = "SELECT field1, field2, field3, field4 FROM marciantest";
#connect
$connect = odbc_connect("$hostname:$dataBase",$username,$passWord) or die("aarrrrrgh, could not connect<br>");
$result = odbc_exec($connect, $query) or die("Couldn't execute statement. Query = $query");
?>
And I get the messages of being unable to connect to the server. Any idea as to what phpMyAdmin might be doing that I can emulate? Or, any idea as to what I'm doing wrong?

TIA
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Is the other server set up to allow connections from outside of localhost?

This needs to be enabled first.... :?
scottz
Forum Newbie
Posts: 3
Joined: Fri Apr 15, 2005 11:04 am

Post by scottz »

Yes. It is set up that way. phpMyAdmin is accessing the database server from my machine with the same user and password that I'm using in my php script attempt.
scottz
Forum Newbie
Posts: 3
Joined: Fri Apr 15, 2005 11:04 am

Post by scottz »

sigh. I've got to be more thorough in checking my code. Improper case of variable names was the culprit.
Post Reply