MSSQL query on Ubuntu 18.04 LTS has stopped working

Asked

Viewed 161 times

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 performed the installation of Ubuntu 18.04 LTS, and did not change anything of the code. However, the query is no longer working.

Follow 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: the number, item and sequence values are entered in a form. However, I have already replaced it 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 didn’t work anymore.

What do I do to make it work again?

  • But it makes a mistake?

  • The error that has returned is 500 (Internal Server Error)

  • This is your local computer or is a production server/website?

  • Is a local server.

  • Go to php.ini and enable errors in display_errors=, leave him like this: display_erros=On, then restart the Apache.

  • I did this and the error returned is: Failed to load Resource: the server responded with a status of 500 (Internal Server Error)

  • Diego must be some syntax error or you didn’t install the sqlsrv on your server. Create an empty file called phpinfo.php and inside it sticks this <?php phpinfo();, it must be in your server’s folder, so call the address http://localhost/phpinfo.php, will load various data, search for error_log and see which error log location, so when you find open this file and look at the last 10 errors in it, copy and paste into your question.

  • Guilherme, both local value and master value are set as no value.

  • Diego go to phpinfo.php again and see how this display_bugs and warns me

  • display_errors = On <line break> Default Value: On <line break> Development Value: On <line break> Production Value: Off

  • You can send a copy of the page generated by phpinfo.php?

  • There is. How do you want me to send?

  • You can email this to my profile https://answall.com/users/3635/guilherme-nascimento?tab=profile

  • Guilherme, thanks for the support. I already sent in your email.

  • Diego display_errors appears as off yet, go to file /etc/php/7.2/apache2/php.ini and look for the line with display_errors change to display_errors=On, then restarts the apache server, if it doesn’t work and keeps popping error 500 then restarts the entire server

  • William I was changing in the wrong place. Now I’ve set it up for On and in phpinfo() it appears as on. Now it is returning the following error: Syntaxerror: Unexpected token < in JSON at position 0. Remembering that I am asking you to return errorThrown through ajax.

  • Diego this part about this strange json, does not seem to have any relation to your code in the question, could put the code in the full please?

  • If you need any more code, please let me know.

Show 13 more comments

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.