msphpsql: UPDATE statement does nothing at all

PHP Driver version or file name

  • 5.9.0

SQL Server version

  • SQL Server Standard 2019 (15.0.2080.9) running on Windows Server 2019 Standard

Client operating system

  • openSUSE Linux 15.2

PHP version

  • 7.4.6

Microsoft ODBC Driver version

  • 17

Problem description

  • I’ve been trying to make UPDATE statements to work, but do anything, although there is no error messages.
  • The SELECT and INSERT statements work fine.

My code:

    $sentenciaQueryUpdate = "UPDATE Contrato SET Estatus='?' WHERE MovID = '?' AND Cliente = '?';";
    $lecturaIni = parse_ini_file($nombreINI, true);

    $dataBase = $lecturaIni['database'];
    $usuario    = $lecturaIni['user'];
    $password = $lecturaIni['password'];

    $connectionOptions = array("Database"  => $dataBase,
                               "UID"                              => $usuario,
                               "PWD"                            => $password,
                               "ReturnDatesAsStrings" => true,
                               "Driver"                          => 'ODBC Driver 17 for SQL Server');

    $connection        = sqlsrv_connect($lecturaIni['dsn'], $connectionOptions);

    if ($connection === false) 
        {
        echo '<FONT color="black">';
        echo "<H1>Error de SQL</H1>";
        echo 'Error en la conexion SQL SERVER a ' . $dataBase;
        echo "<BR/>";
        $errors = sqlsrv_errors();

        foreach ($errors as $error) 
            {
            echo "SQLSTATE: " . $error['SQLSTATE'] . "<BR/>";
            echo "Código: "   . $error['code']     . "<BR/>";
            echo "Mensaje: "  . $error['message']  . "<BR/>";
            }

        die('</FONT>');
        }

    $parameters = [$estatusNuevo, $contratoBusqueda, $clienteBusqueda];
    $statement  = sqlsrv_prepare($connection, $sentenciaQueryUpdate, $parameters);
    
    var_dump($statement);
    echo '<BR>';
    
    if(!$statement) 
        {
        die( print_r( sqlsrv_errors(), true));
        }
    
    $ejecucion = sqlsrv_execute($statement);
        
    var_dump($ejecucion);
    
    if($ejecucion === false) 
        {
        die(print_r( sqlsrv_errors(), true));
        }

    sqlsrv_close($connection);

I’m using sqlsrv_prepare and sqlsrv_execute because I thought that sqlsrv_query was the problem in this issue.

Please, some guidance about what is going on.

Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 25 (12 by maintainers)

Most upvoted comments

You’re so kind, @yitam.

Thanks for your time.

OK @yitam,

I appreciate your time and effort. If I can find the way to solve it, I’ll let you know.

Thanks a lot.