查询适用于phpmyadmin,但不适用于PHP代码

时间:2016-08-13 17:46:29

标签: php mysql mysqli

我有以下脚本,查询工作正常,因为它带来了所需的结果,但是,在日志中,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

第46行是:$stmt->execute();

可能出现什么问题? functions.php文件内部是mysqli的变量$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>

1 个答案:

答案 0 :(得分:-1)

尝试更改错误处理,根据PDO准备函数http://php.net/manual/en/pdo.prepare.php的文档,它可以返回false或pdoexception,我假设它现在返回false,当你得到异常时var_dumping可能会帮助< / p>