MSSQL Query on Ubuntu 18.04 LTS stopped working

0

I have a program that has been running on Ubuntu-server 17 for some time. This system performs queries on a database server with MSSQL 2008. I did the installation of Ubuntu 18.04 LTS, and did not change any of the code. However, the query is no longer working.

Here is the code I'm using:

CONNECTION CODE

$serverName = "IP OF MY SERVER";
$connectionOptions = array(
    "Database" => "DB NAME",
    "Uid" => "USER",
    "PWD" => "PASSWORD"
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
//Select Query
$tsql = "SELECT @@Version as SQL_VERSION";
//Executes the query
$getResults = sqlsrv_query($conn, $tsql);
//Error handling

if ($getResults == FALSE)
    die(FormatErrors(sqlsrv_errors()));

sqlsrv_free_stmt($getResults);

function FormatErrors($errors) {
    /* Display errors. */
    echo "Errors: <br/>";
foreach ($errors as $error) {
    echo "SQLSTATE: " . $error['SQLSTATE'] . "<br/>";
    echo "Code: " . $error['code'] . "<br/>";
    echo "Message: " . $error['message'] . "<br/>";
}
}

AJAX CODE : Number, item, and sequence values are reported on a form. However, I already replaced with existing values in the database to test and the error persisted.

$.ajax({
                            url: 'producao/funcoes/consultaop.php',
                            async: false,
                            data: {
                                "numero": numero,
                                "item": item,
                                "sequencia": sequencia
                            },
                            type: 'post',
                            dataType: 'json',
                            cache: false,
                            beforeSend: function (xhr) {
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                alert("Erro na query "+errorThrown);
                            },
                            success: function (dados) {
                                p = dados.split(" - ");
                                produto = p[0];
                            }
                        });

QUERY CODE

include '../../bd/conexaomssql.php';

$numero = $_POST['numero'];
$item = $_POST['item'];
$sequencia = $_POST['sequencia'];

$consulta = "SELECT B1_DESC FROM SB1010 INNER JOIN SC2010 ON B1_COD = C2_PRODUTO WHERE C2_NUM+C2_ITEM+C2_SEQUEN = '$numero" . "$item" . "$sequencia'";

$query = sqlsrv_query($conn, $consulta);

if ($query == FALSE) {
    echo "Não encontrou!!";
}

$codproduto = "";
while ($linha = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) {
    $codproduto = $linha['B1_DESC'];
}
echo (json_encode($codproduto));

The current version of PHP is 7.2.5.

Remembering that there was no change in the code after the Ubuntu update. It just did not work anymore.

What do I do to get back to work?

    
asked by anonymous 24.05.2018 / 17:31

1 answer

0

In version 17 it was not necessary to install the ssql driver. In the case of this update to 18.04, I had to install and configure it as follows: link

I followed the procedure following the contribution of Guilherme Nascimento :

  

"... should be some syntax error or you have not installed sqlsrv on your server ..."

    
25.05.2018 / 14:03