Jump to content

MS SQL PHP Connection Test Apache2 Server


kat35601

Recommended Posts

I created this to test the connection to my ms sql server with a web page. I can connect with isql with out fail.

when I open this I get

 

PHP SQL Test

END PHP SQL Test

 

I was expecting to get sql data between the above lines. What am I doing wrong.

 

 

<html>
<head>
<title>PHP SQL Test</title>
</head>
<body>
<p> PHP SQL Test </p>

<?
$conn =odbc_connect("datasource","user","password");
if(!$conn) {
    exit("Connection Failed: " . $conn);
}

$sql="SELECT top 10 * from WIP_master";
$rs =odbc_exec($conn,$sql);
print_r($rs);
if(!$rs){
exit("Error in SQL");
}
odbc_close($conn);
?>
<p> End PHP SQL Test </p>
</body>
</html>

There may be other problems that aren't obvious...

 

You need to make a change to your php.ini file: run phpinfo() in a script and it will tell you where you can find the file near the top. Hopefully you do have one.

In there are two settings to change:

error_reporting = -1
display_errors = on
They exist in the file somewhere and probably in two locations: one place describes a bunch of settings, the other is the actual location where the setting is defined. Possibly commented out with a semicolon, in which case you need to uncomment it after changing the value.

 

When you do that, restart Apache and run phpinfo() again. Then look for those two settings - they should have the new values.

 

Then try your script again. There will probably be some kind of error message. Or more than one.

You need to use something like this to get the results from the query

// use a while loop to loop over the rows returned by the query
while($row = odbc_fetch_array($rs))
{
   echo '<pre>' . print_r($row, true) . '</pre>';; // show contents of row
}

Manual page on odbc_fetch_array

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.