Querys have stopped working

Asked

Viewed 79 times

2

I recently made a change to the table and after that SELECT and INSERT INTO stopped working.

At first the INSERT INTO could not include data in the last column that includes (centid), returned column 'centid' cannot be null, but the value was being passed (to resolve this for now I went on to let this column accept NULL and do the UPDATE right away).

Besides this problem with INSERT, a simple SELECT in this table stopped working through PHP.

In all cases I checked if there were empty variables and in all cases nothing is missing, including in the code below, the variable $viagemid is passing the value.

PHP:

$despesas = array();

$sql = "SELECT * FROM `despesas` WHERE `viagemid` = '".$viagemid."'";
$query = $mysqli->query($sql);
$count_desp = mysqli_num_rows($query);
$result = mysqli_fetch_row($query);
while($row =mysqli_fetch_assoc($query)){

    array_push($despesas, $row);
}

In that code specifically, I enabled mysqli_report(MYSQLI_REPORT_ALL); and the return was:

Fatal error: Uncaught Exception 'mysqli_sql_exception' with message 'No index used in query/Prepared statement SELECT * FROM despesas WHERE viagemid = ' 1041 '' in C:\Users\fchagas\Documents\EasyPHP-Devserver-16.1\eds-www\editar_viagem.php:146 Stack trace: #0 C:\Users\fchagas\Documents\EasyPHP-Devserver-16.1\eds-www\editar_viagem.php(146): mysqli->query('SELECT * FROM `...') #1 {main} thrown in C:\Users\fchagas\Documents\EasyPHP-Devserver-16.1 eds-www editar_viagem.php on line 146

Apache log (may be useful):

127.0.0.1 - - [21/Feb/2017:21:18:39 -0300] "POST /nova_viagem.php HTTP/1.1" 200 19992 127.0.0.1 - - [21/Feb/2017:21:18:49 -0300] "GET /eds-modules/phpmyadmin4551x170208222435/sql.php?server=1&db=database&table=despesas&pos=0&token=dad73b6308c6b0dd8911a2c3312bf46e&ajax_request=true&ajax_page_request=true&_nocache=1487722729000434776 HTTP/1.1" 200 7204 127.0.0.1 - - [21/Feb/2017:21:18:49 -0300] "GET /eds-modules/phpmyadmin4551x170208222435/index.php?ajax_request=1&recent_table=1&token=dad73b6308c6b0dd8911a2c3312bf46e&no_debug=true&_nocache=1487722729416685739 HTTP/1.1" 200 1567 127.0.0.1 - - [21/Feb/2017:21:18:54 -0300] "GET /listar_viagem.php HTTP/1.1" 200 60541

  • I ask for 2 favors. Execute the command SHOW CREATE TABLE despesas and put here. Also put the INSERT SQL that is giving error. These two pieces of information, sometimes for themselves, are sufficient to identify the problem.

1 answer

1

This is not an error is just a warning that your query could be better executed. The cause is the MYSQLI_REPORT_ALL reporting beyond warnings, warnings from Erforce.

This warning generated an Exception and took the code out of the normal stream. To get only the errors use: MYSQLI_REPORT_ERROR or MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR in the call for mysqli_report().

  • Thank you, I expressed myself badly. It really doesn’t make a mistake, and this is making my life difficult.

  • @Felipechagas see if so returns any error: $query = $mysqli->query($sql) or die($mysqli->error);

  • Did not return wrong. The code follows as if the result was correct, but the same query directly in the console returns the correct result.

  • @Felipechagas looked at apache log on production server?

  • I never touched this log, so I don’t know what I’m looking for, but I’m going to ask the question the last lines of the log that were recorded during my last test.

Browser other questions tagged

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