PHP SQLite脚本在bindparam指令上失败

时间:2018-10-13 14:19:14

标签: php function sqlite bindparam

我一直在研究类似的问题,这些问题我从中学到了一两个东西,但是我似乎无法在解决问题上取得任何进展。我怀疑我可能是在初始化数据库错误或类似问题。

我的脚本从查询字符串中获取值-

alarmingwrite5.php?frequency=2&durationChoice=5&hourChoice=8&minuteChoice=30&updateRow=UPDATE+NOW

将它们放入变量,然后将值写入sqlite DB表。只有一个表叫做AlarmTimes,5个字段中只有4个需要更新。

在我将值绑定到update语句中的参数之前,一切似乎都很好。

非常感谢您的协助。

<?php
    if($_SERVER['REQUEST_METHOD'] == "GET" and isset($_GET['updateRow']))
        {
            updateDB();
        }
        function updateDB()
        {
            $durationChoice = (integer) $_GET["durationChoice"];
            echo gettype($durationChoice).'<br>'; // check type
            $frequency = (integer)  2;
            echo gettype($frequency).'<br>'; // check type
            $hourChoice = (integer) $_GET["hourChoice"];
            echo gettype($hourChoice).'<br>'; // check type
            $minuteChoice = (integer) $_GET["minuteChoice"];
            echo gettype($minuteChoice).'<br>'; // check type

            $db = new SQLite3('/home/pi/sqliteDB/testdbsqlite3.db');
            $statement = $db->prepare("UPDATE alarmTimes SET alarmLength = :alarmLength, alarmCheck = :alarmCheck, alarmHour = :alarmHour, alarmMinute = :alarmMinute where entryID = 1 ");
            echo('prepped</br>'); // This appears
            $statement->bindParam(":alarmLength", $durationChoice, SQLITE3_INTEGER);
            echo('parameter alarmLength bound'); // **** This does not appear so problem is with binding parameters or the values being bound****


            $statement->bindParam(":alarmCheck", $frequency, SQLITE3_INTEGER);
            $statement->bindParam(":alarmHour", $hourChoice, SQLITE3_INTEGER);
            $statement->bindParam(":alarmMinute", $minuteChoice, SQLITE3_INTEGER);
            echo('parameters bound'); // **** This does not appear ****
            $statement->execute();
            echo('executed'); // **** This does not appear ****

            // redirect to same page **** does not happen
            ob_start();
            $url = 'alarmingwrite5.php';
            while (ob_get_status()) 
                {
                    ob_end_clean();
                }
            header( "Location: $url" );

        }
?>

0 个答案:

没有答案