Page 1 of 1

[SOLVED] Trouble connecting to a remote mysql db

Posted: Fri Apr 15, 2005 11:36 am
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

Posted: Fri Apr 15, 2005 11:48 am
by Chris Corbyn
Is the other server set up to allow connections from outside of localhost?

This needs to be enabled first.... :?

Posted: Fri Apr 15, 2005 12:04 pm
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.

Posted: Fri Apr 15, 2005 2:11 pm
by scottz
sigh. I've got to be more thorough in checking my code. Improper case of variable names was the culprit.