0

I get an error while atempting to update a row in my table

$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";
}

I get the following error code when i try to execute the code above:

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

I also tried to add some parameters before executing queries:

$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");

This is an example of the query string generated bellow :

UPDATE [F_ARTICLE] SET [AR_Design] = 'azertyuuio', [FA_CodeFamille] = 'J', [AR_PrixAch] = '153.47', [AR_PrixVen] = '145.7965', [AR_Coef] = '0.95', [AR_PoidsNet] = '0', [AR_UnitePoids] = '2' WHERE [AR_Ref] = '801-0198'

When i paste this line into sql server management studio it's working fine. It's not working in my project.

Thanks for your help

ebelair
  • 844
  • 11
  • 27

1 Answers1

0

After several reserch, i found the solution here: Error while updating Database with mssql_query

So i updated my code to this:

    $conn->executeQuery("
SET
  ANSI_NULLS,
  QUOTED_IDENTIFIER,
  CONCAT_NULL_YIELDS_NULL,
  ANSI_WARNINGS,
  ANSI_PADDING
ON;
");
Community
  • 1
  • 1
ebelair
  • 844
  • 11
  • 27