dlebowski Posted September 23, 2009 Share Posted September 23, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/175237-solved-odbc_connect-command-line-it-works-browser-is-blank/ Share on other sites More sharing options...
dlebowski Posted September 23, 2009 Author Share Posted September 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175237-solved-odbc_connect-command-line-it-works-browser-is-blank/#findComment-923652 Share on other sites More sharing options...
nuttycoder Posted September 23, 2009 Share Posted September 23, 2009 have you got error reporting turned on? Quote Link to comment https://forums.phpfreaks.com/topic/175237-solved-odbc_connect-command-line-it-works-browser-is-blank/#findComment-923664 Share on other sites More sharing options...
dlebowski Posted September 23, 2009 Author Share Posted September 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175237-solved-odbc_connect-command-line-it-works-browser-is-blank/#findComment-923668 Share on other sites More sharing options...
dlebowski Posted September 23, 2009 Author Share Posted September 23, 2009 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:. Quote Link to comment https://forums.phpfreaks.com/topic/175237-solved-odbc_connect-command-line-it-works-browser-is-blank/#findComment-923692 Share on other sites More sharing options...
dlebowski Posted September 23, 2009 Author Share Posted September 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175237-solved-odbc_connect-command-line-it-works-browser-is-blank/#findComment-923811 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.