cooperd Posted December 3, 2009 Share Posted December 3, 2009 Hello, I am trying to query an SQL Server database from a php page. I am using the following code: $sql="SELECT [Adjust] FROM dbo.[ProjectData] WHERE ([ProjectNumber] = '".$_GET[pn]."')"; $res = mssql_query($sql, $conn); $row = mssql_fetch_assoc($res); echo sprintf($row["Adjust"]); This gives me a query value string SELECT [Adjust] FROM dbo.[ProjectData] WHERE ([ProjectNumber] = '1077') . When I execute this query in SQL Server Management Studio I get the correct result, but the above code is returning a null value. I know that my connection string is good. If anyone could help me out I would appreciate it. Thanks, Dave Link to comment https://forums.phpfreaks.com/topic/183910-mssql-query/ Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2009 Share Posted December 3, 2009 try this and tell us what you see $res = mssql_query($sql, $conn) or die(mssql_error($conn)); I think that should work Link to comment https://forums.phpfreaks.com/topic/183910-mssql-query/#findComment-970875 Share on other sites More sharing options...
premiso Posted December 3, 2009 Share Posted December 3, 2009 Have you tried echoing out the $sql and making sure all the data there is what you expect it to be? That would be my first check and if you could post the results after you echo out the $sql that would be great EDIT: Try that after seeing if there was an error as rajiv suggested. Link to comment https://forums.phpfreaks.com/topic/183910-mssql-query/#findComment-970876 Share on other sites More sharing options...
cooperd Posted December 4, 2009 Author Share Posted December 4, 2009 Sorry guys, it was my bad, I was working on this at the end of the day yesterday and didn't realize that I forgot to declare '$conn' in that function. Thanks for the reply's though. Link to comment https://forums.phpfreaks.com/topic/183910-mssql-query/#findComment-971329 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.