I need to be able to query an MS SQL database from within a drupal module.
I have php code that accomplishes this already written, tested, and working in production.
For some reason, this same code that connects to the server, doesn't work from within the drupal module. Any ideas? For some reason, when I uncomment the ($db = "Files") line from this code, I get the dreaded white page. If I leave it commented, it fails to connect for obvious reasons. This same code works from the same apache web server when ran from a raw php page.

PLEASE HELP...

Here is the test code I wrote to test this functionality:

else if ($op == "view") {

/**
* Connect to and query the MS SQL db on seneca
*/

$block_content = ''; // define a string to hold the block content
$block['subject'] = "Testing"; // define the block subject

$serverName = "my_server_name"; // DB server name

/**
* Uncommenting the following code causes the website to "white-page".
* White-page is normally due to syntax errors, but not in this case.
* It must have an issue trying to connect to the DB server from within drupal.
* This could be drupal configuration settings??????
*/

// $db = "Files"; // DB name

/***************************************************************************/

$connectionInfo = array ("Database"=>$db); // create an array to hold the connection info
$conn = sqlsrv_connect( $serverName, $connectionInfo); // connect to the specified database (windows authentication)

if( $conn === false ) // if the connection fails
{
$block_content .= t("Unable to connect to the database.") . "
"; // print an error message
if (($errors = sqlsrv_errors()) != null)
{
foreach ($errors as $error)
{
$block_content .= $error['message'] . "
";
$block_content .= $error['code'] . "
";
}
}
$block['content'] = $block_content;
return $block; // and exit
}

Comments

Drupal has an easy to use api for this. See How to connect to multiple databases within Drupal for more info.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

This is only for connecting to other MySQL db's. I need to connect to a MS SQL db.

yeah-- sorry about that, I'm so used to seeing mysql I totally brain spasmed on the 'ms' part of your post.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Not sure if this will help you, but MS just released a pdo driver for MS SQL. This will definitly help in Drupal 7 but that doesn't help you now.
http://blogs.msdn.com/sqlphp/archive/2010/04/19/sql-server-driver-for-ph...

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

Microsoft has submitted a patch for Drupal 6.xx, feedback on the patch has been incorporatied. The patch is awaiting approval from the core Drupal developlers:https://code.launchpad.net/~drupal-sql-server/pressflow/drupal-sql-server/

Ashay
Program Manager, SQL Server Driver for PHP
Microsoft Corp.

Ashay

So when will this patch be available? Where do I get it?

the PDO driver? I think they had some links in their presentation
http://sf2010.drupal.org/conference/sessions/drupal-7-and-microsoft-sql-...

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain