Forum Moderators: coopster

Message Too Old, No Replies

No ouput after ADODB connection attempt?

The php function seems to stop any subsequent html output.

         

NooK

11:48 am on Aug 24, 2007 (gmt 0)

10+ Year Member



I am trying to connect to a MSSQL Database but I am having some problems.

I create this function in a file (Called functions.php)


function connectToDB()
{
$DBServer = 'serveraddress;
$DBUsername = 'login';
$DBPass = 'password';
$DBName = 'dbName';

$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$conn->Open("PROVIDER=SQLOLEDB.1;SERVER=".$DBServer.";DATABASE=".$DBName.";UID=".$DBUsername.";PWD=".$DBPass);
$rs = $conn->Execute("SELECT * FROM caars"); // Recordset
}

And in another php file I call the function.

My problem is that when the execution query fails on the server (For example if the table doesnt exist) any following html or php code after the function call is not shown on the browser (But if the query is valid and is successfully executed it all works).

Can anybody help me? Is there anyway to display what the reason might be for the query not being executed (Some error message or something similar)? I have tried the methods on this webpage

<snip>

But didnt get any to do anything or show any error message.

As an example imagine the html file that calls the functions


<HTML><HEAD><TITLE>Test Page</TITLE></HEAD>
<BODY>
<?php connectToDB();?>

This is a test webpage
</BODY>
</HTML>

If the query goes through I see the string "This is a test webpage" but if it does not I see a blank page (I'd like to see the rest of the page if possible even if the query fails and also some error message if possible).

Best Regards

NooK

[edited by: dreamcatcher at 12:27 pm (utc) on Aug. 24, 2007]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]

eelixduppy

6:18 pm on Aug 27, 2007 (gmt 0)



When a fatal error occurs it will stop the execution of the file, pretty much leaving you with a blank page if you error reporting [php.net] isn't turned on. Try showing errors and run a query that is going to fail. You have to handle the bad query properly so you do not get a fatal error.

NooK

1:13 pm on Aug 28, 2007 (gmt 0)

10+ Year Member



Still no go. I have set the error lvl to max and I am getting no error at all when I try query a table that does not exist. Is there no way to get an error message?

Best Regards

NooK

NooK

12:15 pm on Aug 29, 2007 (gmt 0)

10+ Year Member



I have managed to get errors to show up finally. Thank you for the support.

Best Regards

NooK