更新时ZF 2 MS SQL Server错误1934

时间:2014-11-03 16:35:07

标签: sql-server-2008 zend-framework2

我在试图更新表格中的行时遇到错误

$adapter = new Zend\Db\Adapter\Adapter([
    'driver'   => 'Pdo_dblib',
    'hostname' => 'SRVSQL',
    'database' => 'TDEV',
    'username' => 'sa',
    'password' => 'xxxx'
]);

$update = $sql->update('F_ARTFOURNISS')
    ->set([
        'AF_RefFourniss' => $fournRef,
        'AF_PrixAch'     => $fournPxAchat,
        'AF_Remise'      => $fournRemise,
        'AF_CodeBarre'   => $fournGenCode
    ])
    ->where(['AR_Ref' => $ref]);

try {
    $statement = $sql->prepareStatementForSqlObject($update);
    $results = $statement->execute();
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}

当我尝试执行上面的代码时,我收到以下错误代码:

Statement could not be executed (HY000 - 1934 - General SQL Server error: Check messages from the SQL Server [1934] (severity 16) [(null)] - -1 - 16)

我还尝试在执行查询之前添加一些参数:

$adapter->query("SET ANSI_WARNINGS ON");
$adapter->query("SET ANSI_PADDING ON");
$adapter->query("SET ANSI_NULLS ON");
$adapter->query("SET QUOTED_IDENTIFIER ON");
$adapter->query("SET CONCAT_NULL_YIELDS_NULL ON");

这是下面生成的查询字符串的示例:

更新[F_ARTICLE]设置[AR_Design] =' azertyuuio',[FA_CodeFamille] =' J',[AR_PrixAch] =' 153.47',[AR_PrixVen ] =' 145.7965',[AR_Coef] =' 0.95',[AR_PoidsNet] =' 0',[AR_UnitePoids] =' 2' ;在哪里[AR_Ref] =' 801-0198'

当我将此行粘贴到sql server management studio时,它工作正常。它在我的项目中不起作用。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

经过多次研究,我在这里找到了解决方案:Error while updating Database with mssql_query

所以我将我的代码更新为:

    $conn->executeQuery("
SET
  ANSI_NULLS,
  QUOTED_IDENTIFIER,
  CONCAT_NULL_YIELDS_NULL,
  ANSI_WARNINGS,
  ANSI_PADDING
ON;
");