dt246813579 2012-08-21 12:51 采纳率: 0%
浏览 77
已采纳

无法使用PDO将值插入MSSQL

I'm using PDO to communicate with my database from PHP code and i have the following code:

$sql = "SELECT <Column> FROM <tablename>";

it works for my mssql database, however when i try to insert some data into it with

$sql = "INSERT INTO <tablename> ( <Column> ) VALUES ( '1' )";

it fails.

why?

it's funny, but when i run that code from my SQL Server Management Studio - it works. I can't get it...

The error i get is:

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

Thanks in advance...

  • 写回答

1条回答 默认 最新

  • douchi2022 2012-08-21 12:54
    关注

    Explanation

    This error occurs at run time when an attempt is made to use a null value while inserting or updating a column that does not allow null values.

    Action

    If this error occurs when you are running an UPDATE or INSERT statement, verify that the data inserted or updated matches the column definition for the affected table.

    Inserting or updating a column does not allow null values.

    Check this: http://www.lcard.ru/~nail/sybase/error/3742.htm or this: http://technet.microsoft.com/en-us/library/aa258724(v=sql.100).aspx

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?