Query Mysqli SUM does not return with result

2

I'm trying to sum a column using the SUM method of mysqli. The problem is that my query does not return with results. My code is this:

   $sql = 'SELECT SUM(size) as soma, porta FROM ''
        .$this->options['db_table'].'' WHERE 'porta'=?';
    $query = $this->db->prepare($sql);
    $query->bind_param('s', $file->porta);
    $query->execute();
    $query->bind_result(
        $soma
    ); 

   $query->close();

   echo $soma;

What could be wrong? Remember that all other queries without using SUM () work perfectly.

    
asked by anonymous 09.09.2014 / 05:28

1 answer

5

Failed to use fetch :

$sql   = 'SELECT SUM(size) as soma, porta FROM ''.$this->options['db_table'].'' WHERE 'porta'=?';
$query = $db->prepare($sql);
$query->bind_param('s', $file->porta);
$query->execute();
$query->bind_result($soma); 

if($query->fetch()){
    echo 'result is ' . $soma;
}
$query->close();
    
09.09.2014 / 06:37