0

I have the following script, the query works fine as it brings the desired results, however, on the logs, the following error comes up in PHP:

[Sat Aug 13 11:04:14.025454 2016] [:error] [pid 17819] [client 192.168.11.1:45339] PHP Fatal error:  Call to a member function execute() on a non-object in /var/www/html/hs-curweek.php on line 46

Line 46 is this: $stmt->execute();

What could possible be wrong? Inside the functions.php file is the variable for mysqli called $DB

<?php
    printFooter();
?>
<div class="container-fluid">
    <div class="row">
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <th>Nombre</th>
                    <th>Recurso</th>
                    <th>Motivo</th>
                    <th>Clase</th>
                    <th>Grado</th>
                    <th>Fecha</th>
                </thead>
                <tbody>
                    <?php
                        $query = "SELECT t6.USERNAME as Nombre, t2.RESOURCENAME as Recurso, RESERVATION_DESCRIPTION  as Descripción, t4.CLASSNAME, t5.GRADENAME, CONCAT( CAST( DATE_FORMAT( RESERVATIONDUEDATE,  '%M %D %Y de %l:%i %p' ) AS CHAR ) , ' a ', CAST( DATE_FORMAT( RESERVATIONEXPIREDATE,  '%l:%i %p' ) AS CHAR ) ) as Fecha
                        FROM  `reservation` t1
                        INNER JOIN  `resource` t2 ON t1.RESOURCEID = t2.RESOURCEID
                        INNER JOIN schedule_intermediate t3 ON t1.SCHEDULEID_GENERATED = t3.SCHEDULEID_GENERATED
                        INNER JOIN class t4 ON t1.CLASSID = t4.CLASSID
                        INNER JOIN grade t5 ON t1.GRADEID = t5.GRADEID
                        INNER JOIN users t6 ON t1.USERID = t6.USERID
                        WHERE (
                        YEARWEEK(  `RESERVATIONDUEDATE` , 1 ) = YEARWEEK( CURDATE( ) , 1 )
                        )
                        AND (
                        t2.RESOURCELOCATIONID =3
                        OR t2.RESOURCELOCATIONID =4
                        )";
                        $stmt = $DB->prepare($query);
                        $stmt->execute();
                        $stmt->bind_result($nombre, $recurso, $motivo, $clase, $grado, $fecha);
                        while($stmt->fetch()){
                            echo '<tr>';
                            echo '<td>'.$nombre.'</td>';
                            echo '<td>'.$recurso.'</td>';
                            echo '<td>'.$motivo.'</td>';
                            echo '<td>'.$clase.'</td>';
                            echo '<td>'.$grado.'</td>';
                            echo '<td>'.$fecha.'</td>';
                            echo '</tr>';
                        }
                    ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
CodeTrooper
  • 1,890
  • 6
  • 32
  • 54

1 Answers1

-1

Try changing your error handling, acording to documentation of PDO prepare function http://php.net/manual/en/pdo.prepare.php it can return false or pdoexception, I'm assuming it returns false right now, var_dumping it when you get the exception might help

Kaemic
  • 14
  • 4