kat35601 Posted October 10, 2014 Share Posted October 10, 2014 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> Quote Link to comment https://forums.phpfreaks.com/topic/291565-ms-sql-php-connection-test-apache2-server/ Share on other sites More sharing options...
requinix Posted October 10, 2014 Share Posted October 10, 2014 Use the normal, long open tags. Short ones only work if you happen to have PHP set up to accept them. (= is an exception which will always work - with recent versions of PHP.) Quote Link to comment https://forums.phpfreaks.com/topic/291565-ms-sql-php-connection-test-apache2-server/#findComment-1493291 Share on other sites More sharing options...
kat35601 Posted October 10, 2014 Author Share Posted October 10, 2014 when I <?php I only get PHP SQL Test and no SQL output or END PHP SQL Test bythe way this is my first ever PHP code and I had to google long open tags to see what you meant. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/291565-ms-sql-php-connection-test-apache2-server/#findComment-1493293 Share on other sites More sharing options...
requinix Posted October 10, 2014 Share Posted October 10, 2014 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 = onThey 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. Quote Link to comment https://forums.phpfreaks.com/topic/291565-ms-sql-php-connection-test-apache2-server/#findComment-1493297 Share on other sites More sharing options...
Ch0cu3r Posted October 11, 2014 Share Posted October 11, 2014 Could you tell us how you are testing the code? You should be running the code from http://localhost and the code should be saved in a file ending in a .php extension. Quote Link to comment https://forums.phpfreaks.com/topic/291565-ms-sql-php-connection-test-apache2-server/#findComment-1493313 Share on other sites More sharing options...
kat35601 Posted October 13, 2014 Author Share Posted October 13, 2014 error message Fatal error: Call to undefined function odbc_connect() in /var/www/html/sql.php on line 9 I am running this from http://localhost/sql.php Quote Link to comment https://forums.phpfreaks.com/topic/291565-ms-sql-php-connection-test-apache2-server/#findComment-1493458 Share on other sites More sharing options...
kat35601 Posted October 13, 2014 Author Share Posted October 13, 2014 I installed php5-odbc and now I get Resource id#3. So it looks like its working I just now have to figure out how to get the results out. Thanks PHP SQL Test Resource id #3 End PHP SQL Test Quote Link to comment https://forums.phpfreaks.com/topic/291565-ms-sql-php-connection-test-apache2-server/#findComment-1493461 Share on other sites More sharing options...
Ch0cu3r Posted October 13, 2014 Share Posted October 13, 2014 (edited) 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 Edited October 13, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/291565-ms-sql-php-connection-test-apache2-server/#findComment-1493464 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.