Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP / PDO / MSSQL how to get error informations?

I've done a lot of searching, but can't find anything about my issue. I'm using PDO with Driver PDO_DBLIB to access a MS SQL database. I generally use prepared statements, but if any query fails I don't get any additional information about the error except for this:

General SQL Server error: Check messages from the SQL Server [241] (severity 16) [(null)]

Does anyone have a hint as to how do I retrieve more information about the error (syntax error at...)?

best regards

Michael

like image 275
Michael Avatar asked Mar 31 '11 09:03

Michael


1 Answers

To find the error message:

-- SQL 2005+
select * from sys.messages where message_id = 241
-- SQL 2000
select * from sysmessages where error = 241

It appears that PDO is removing the actual error message text for some reason, but since the documentation says that PDO_DBLIB is experimental, this may simply be a bug.

You should also be aware that DBLIB has been deprecated by Microsoft since SQL 2005, so you should almost certainly use a different library for connecting to MSSQL.

like image 131
Pondlife Avatar answered Sep 28 '22 01:09

Pondlife