jperez260 Posted January 28, 2017 Share Posted January 28, 2017 Hello All, I'm trying to use PHP to post to MSSQL server, I can get a connection however when I attempt my MSSQL Statement the query just won't work. This is most troubling, anyone have any suggestions Here's my code $conn = mssql_connect( 'myServer', "username", 'password', 'database' ) or die('Error Connecting'); $sql = "INSERT INTO Employees (Area, isTicketRep) VALUES ('789456', '1')"; mssql_query($conn, $sql) or die('Error Querying MSSQL Database'); mssql_close($conn); I have tried an if statement to ensure a connection, I have a connection....however the query just wont execute. There are numerous column on my database table but I'm only submitted selected field. In addition the actual table is called "Employees" but on the server reads "dbo.Employees". My Database is called "cs_all" Just won't seem to query, thanks in advance for any suggestions Quote Link to comment https://forums.phpfreaks.com/topic/303047-mssql-statement/ Share on other sites More sharing options...
Jacques1 Posted January 28, 2017 Share Posted January 28, 2017 Can you be a bit more specific than “doesn't work”? Are you getting your “Error Querying ...” message? Does the program crash? Does it keep running but has no effect? The mssql_query() function expects the query as the first argument (read the manual), so I'm fairly sure you do get a proper error. Quote Link to comment https://forums.phpfreaks.com/topic/303047-mssql-statement/#findComment-1542056 Share on other sites More sharing options...
jperez260 Posted January 28, 2017 Author Share Posted January 28, 2017 (edited) Sorry... Nothing Crashes Seems like the "or die" is stopping the INSERT I don't get any detail of the error, maybe since I don't have a way to print the error. The error I get is what I have in the "or die" container as text. I've used tsql from the command line and I can get it to INSERT to the mssql server but from my php script no deal. is there way you can recommend to print out errors so i can dig deeper? Edited January 28, 2017 by jperez260 Quote Link to comment https://forums.phpfreaks.com/topic/303047-mssql-statement/#findComment-1542058 Share on other sites More sharing options...
Jacques1 Posted January 28, 2017 Share Posted January 28, 2017 I recommend you read my reply: The mssql_query() function expects the query as the first argument But, yes, you definitely need to work on your error reporting. This or die(...) pattern may be very popular, but it's nonsense. When an error happens, you want two things: Log the exact error message reported by MS SQL Print a generic error message on the screen for the user (and set the appropriate HTTP response code). Unfortunately, the mssql_* functions are old and crusty, so this will require a lot of work. Do you have to use them? There are MS SQL drivers for the PDO interface which are much more modern and can do the error reporting automatically. Quote Link to comment https://forums.phpfreaks.com/topic/303047-mssql-statement/#findComment-1542060 Share on other sites More sharing options...
Barand Posted January 28, 2017 Share Posted January 28, 2017 Note The PDO_SQLSRV extension is only compatible with PHP running on Windows. For Linux, see ODBC and » Microsoft's SQL Server ODBC Driver for Linux. Quote Link to comment https://forums.phpfreaks.com/topic/303047-mssql-statement/#findComment-1542061 Share on other sites More sharing options...
jperez260 Posted January 30, 2017 Author Share Posted January 30, 2017 Note I'm running a debian apache server Quote Link to comment https://forums.phpfreaks.com/topic/303047-mssql-statement/#findComment-1542129 Share on other sites More sharing options...
Jacques1 Posted January 31, 2017 Share Posted January 31, 2017 Then use ODBC. You have my permission. Quote Link to comment https://forums.phpfreaks.com/topic/303047-mssql-statement/#findComment-1542130 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.