問題描述
在 SQL Server 2005 中向表中添加計算列后,我在 INSERT
上收到以下消息,僅通過 PHP(使用 PDO)它在 SQL Server Management Studio 中工作正常.
After adding a computed column to a table in SQL Server 2005 I am getting the following message on INSERT
, only via PHP (using PDO) it's working fine in SQL Server Managment Studio.
為了確保一切正確,我使用 SQL Server Profiler 設(shè)置了跟蹤并將 INSERT 語句復(fù)制/粘貼到 SQL Server Management Studio.它在 SSMS 中運行良好,但在 PHP 中繼續(xù)失敗.
To ensure I had everything correct I setup a trace with SQL Server Profiler and copy/pasted the INSERT statement into SQL Server Managment Studio. It ran just fine in SSMS, but continues to fail in PHP.
添加聯(lián)系人時出錯:SQLSTATE[HY000]:一般錯誤:1934 一般 SQL服務(wù)器錯誤:檢查來自 SQL Server [1934] 的消息(嚴(yán)重性 16)[(空)]
Error adding contact: SQLSTATE[HY000]: General error: 1934 General SQL Server error: Check messages from the SQL Server [1934] (severity 16) [(null)]
推薦答案
原來問題與 SET 參數(shù)有關(guān).我使用了從 這里.確定在 SQL Server Management Studio(插入工作的地方)中設(shè)置了哪些選項.然后在我的插入語句之前將每個放在 exec 中導(dǎo)致事情再次工作.我不需要保留所有選項,所以下面我展示了使其工作所需的選項.
Turns out the problem had to do with the SET parameters. I used the code below obtained from Here. To determine which options were set in SQL Server Management Studio (where the insert worked). Then placing each of those in an exec prior to my insert statement caused things to work again. I didn't need to keep all the options, so below I show the ones which were required to get it working.
DECLARE @options INT
SELECT @options = @@OPTIONS
PRINT @options
IF ( (1 & @options) = 1 ) PRINT 'DISABLE_DEF_CNST_CHK'
IF ( (2 & @options) = 2 ) PRINT 'IMPLICIT_TRANSACTIONS'
IF ( (4 & @options) = 4 ) PRINT 'CURSOR_CLOSE_ON_COMMIT'
IF ( (8 & @options) = 8 ) PRINT 'ANSI_WARNINGS'
IF ( (16 & @options) = 16 ) PRINT 'ANSI_PADDING'
IF ( (32 & @options) = 32 ) PRINT 'ANSI_NULLS'
IF ( (64 & @options) = 64 ) PRINT 'ARITHABORT'
IF ( (128 & @options) = 128 ) PRINT 'ARITHIGNORE'
IF ( (256 & @options) = 256 ) PRINT 'QUOTED_IDENTIFIER'
IF ( (512 & @options) = 512 ) PRINT 'NOCOUNT'
IF ( (1024 & @options) = 1024 ) PRINT 'ANSI_NULL_DFLT_ON'
IF ( (2048 & @options) = 2048 ) PRINT 'ANSI_NULL_DFLT_OFF'
IF ( (4096 & @options) = 4096 ) PRINT 'CONCAT_NULL_YIELDS_NULL'
IF ( (8192 & @options) = 8192 ) PRINT 'NUMERIC_ROUNDABORT'
IF ( (16384 & @options) = 16384 ) PRINT 'XACT_ABORT'
以下是我最終需要的選項:
Here are the options I ended up needing:
$dbPDO->exec("SET ANSI_WARNINGS ON");
$dbPDO->exec("SET ANSI_PADDING ON");
$dbPDO->exec("SET ANSI_NULLS ON");
$dbPDO->exec("SET QUOTED_IDENTIFIER ON");
$dbPDO->exec("SET CONCAT_NULL_YIELDS_NULL ON");
更新:似乎 FK 約束導(dǎo)致了以下錯誤.以上也修復(fù)了這個錯誤.
Update: It seems FK constraints resulted in the following error. The above fixed this error as well.
SQLSTATE[HY000]:一般錯誤:8624 一般 SQL Server 錯誤:檢查來自 SQL Server 的消息 [8624](嚴(yán)重性 16)[(null)]
SQLSTATE[HY000]: General error: 8624 General SQL Server error: Check messages from the SQL Server [8624] (severity 16) [(null)]
這篇關(guān)于SQL Server 錯誤 1934 發(fā)生在 INSERT 到帶有計算列 PHP/PDO 的表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!