I am having problems connecting to a remote database from my local development environment.
I’m running XAMPP, so I’m using PHP5 and Apache and I need to connect to a remote Windows 2003 server running MS SQL Server 2005.
I have managed to connect to the databse using ODBC by setting up a DSN on my local machine. This works fine using the following code:
[code]
$db_user = “dp_username”; // Db Username.
$db_pass = “dp_password”; // Db Password.
$db_odbc = “db_DSN”; // ODBC DSN (Data Source Name).
$db_table = “db_table”; // Db Table being used.
$db_connect = odbc_connect($db_odbc, $db_user, $db_pass);
Something I’ve realised is that if I want to move this script to another remote server, i.e. a live hosting space. I will need to (some how) create another DSN on that new host, but if I do not have root access I probably cant do this.
This has forced me to try the MSSQL set of functions but I have been unsuccessful in connecting to the same remote server. I am using the exact same connection details as before, the only change is no DSN but a domain name for my server and a port number (server.mydomain.com:1433).
This is the code I’m using:
[code]
if (!defined(“DB_SERVER”)) define(“DB_SERVER”, “server.mydomain.com:1433”);
if (!defined(“DB_NAME”)) define(“DB_NAME”, “db_table”); // Database name
if (!defined(“DB_USER”)) define (“DB_USER”, “dp_username”); // MSSQL Server username
if (!defined(“DB_PASSWORD”)) define (“DB_PASSWORD”, “dp_password”); // MSSQL Server password
// database connection
function connect_db() {
$conn_str = mssql_connect(DB_SERVER, DB_USER, DB_PASSWORD);
mssql_select_db(DB_NAME, $conn_str);
}
I would really appreciate any thoughts on how to solve my connection connondrum.
Regards,
P.