Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/303047-mssql-statement/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/303047-mssql-statement/#findComment-1542056
Share on other sites

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 by jperez260
Link to comment
https://forums.phpfreaks.com/topic/303047-mssql-statement/#findComment-1542058
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/303047-mssql-statement/#findComment-1542060
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.