[SOLVED] Trouble connecting to a remote mysql db
Posted: Fri Apr 15, 2005 11:36 am
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:
and
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
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!");
?>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");
?>TIA