Jump to content

[SOLVED] odbc_connect Command Line it Works, Browser Is Blank


dlebowski

Recommended Posts

All,

 

I have successfully created an ODBC connection from my LINUX web server to a Windows SQL server on our network.  When I run my php code from the command line, it works perfectly.  When I try and pull the same page up in my browser, all I get is a blank page.  Has anyone come across this before?

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<body>
<?
# connect to a DSN "mssql" with a user and password "mypassword" 
$connect = odbc_connect("mssql", "sa", "mypassword");

# query the users table for name and surname
$query = "SELECT DEPT FROM DEPT";

# perform the query
$result = odbc_exec($connect, $query);

# fetch the data from the database
while(odbc_fetch_row($result))
{
$name = odbc_result($result, 1);
print("$name \n");

}

# close the connection
odbc_close($connect); ?> 
</body>
</html>

I now am getting this in my browser with debugging turned on:

 

Warning: odbc_connect() [function.odbc-connect]: SQL error: [unixODBC][FreeTDS]

Unable to connect to data source, SQL state S1000 in SQLConnect

 

It will works correctly when I run it via the command line.  So this error only occurs when I try to view my page in a browser.  Any ideas at all would be appreciated.  thanks.

 

 

Yes.  It's giving me this error running my php script via a browser:

 

Warning: odbc_connect() [function.odbc-connect]: SQL error: [unixODBC][FreeTDS]

Unable to connect to data source, SQL state S1000 in SQLConnect

 

If I run the php script via the command line on my web server, it works perfect.

Here is what it looks like when I run my script test.php from the command line:

 

 

[root@webserver aru]# php test.php

PHP Warning:  Module 'mysql' already loaded in Unknown on line 0

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html lang="en">

<body>

ADMN-Administration

ADMT-Patient Access - ADT

ADTE-Pt Access- ER ADT

</body>

</html>[root@webserver aru]#

 

 

Now if I browse to it in my browser, it gives me the Warning:.

I managed to figure out what the problem was SELinux (Centos 5) was preventing apache processes from connecting to a the remote MSSQL server.  This would explain why my shell accounts could run the php scrip fine.

 

I resolved this issue by running:

 

setsebool -P httpd_can_network_connect=1

 

This allowed my web server to connect to my MSSQL server and query the data via ODBC.

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.