Error with select in mysql

1

I'm having an error log that does not happen often. On average 1 time per month. Problem is, I'm not picking the error. I'll put my select so you can see if something is wrong.

$result = $mysqli->query("
    SELECT SUM(a.qtd)
    FROM 
        produtos_pedidos a, 
        pedidos b
    WHERE 
        a.id_pedido = b.id 
        and (b.status = 0 or b.status = 4 or b.status = 7)
        and a.id_produto = $produto
        and b.pdv = 'n'
");
$row = mysqli_fetch_array($result);
$qtd_penhora = (float) $row['SUM(a.qtd)'];

The error log is the one here:

[09-Jan-2017 16:56:55 America/Sao_Paulo] PHP Warning:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /var/www/webroot/ROOT/Funcoes/Movimentacao.php on line 35

The line that occurs and error is this one:

$row = mysqli_fetch_array($result);

Is there anything wrong with select?

    
asked by anonymous 10.01.2017 / 11:18

2 answers

1

It means that your query is not executing correctly.

Put these lines before fetch_array () to find out the error:

if (!$result)
   die ($mysqli->error);
    
10.01.2017 / 12:06
-1

Try using the fetch_all :

$mysqli->query("
    SELECT SUM(a.qtd)
    FROM 
        produtos_pedidos a, 
        pedidos b
    WHERE 
        a.id_pedido = b.id 
        and (b.status = 0 or b.status = 4 or b.status = 7)
        and a.id_produto = $produto
        and b.pdv = 'n'
");
$row = $mysqli->fetch_all(MYSQLI_ASSOC);
    
10.01.2017 / 12:52