/    Sign up×
Community /Pin to ProfileBookmark

ODBC versus MSSQL Connections

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);
[/code]

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);
}
[/code]

I would really appreciate any thoughts on how to solve my connection connondrum.

Regards,

P.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @paperclip spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...