fetchArray()在SQLite中不起作用

时间:2016-06-20 12:50:52

标签: php sqlite

我在网络服务器上使用SQLite,直到现在都没有问题。

        $sql = "SELECT * from TeammateCurrent;";
        $ret = $db->query($sql);

        if($ret != false) {

            while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
                $uniqueid = $row['uniqueID'];

                $name = $row['Name'];
                $lineID = $row['LineID'];
                $job = $row['Job'];
                $sunday = $row['Sunday'];
                $monday = $row['Monday'];
                $tuesday = $row['Tuesday'];
                $wednesday = $row['Wednesday'];
                $thursday = $row['Thursday'];
                $friday = $row['Friday'];
                $saturday = $row['Saturday'];
                //echo $name."<br>".$lineID."<br>".$job."<br>".$sunday."<br>".$monday."<br>".$tuesday."<br>".$wednesday."<br>".$thursday."<br>".$friday."<br>".$saturday."<br><br>";

                $sql = "INSERT INTO TeammateHistory (uniqueID, Name,LineID,Job,Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)
                    VALUES (NULL, '$name','$lineID','$job','$sunday','$monday','$tuesday','$wednesday','$thursday','$friday','$saturday');";

                $ret = $db->exec($sql);
                if(!$ret){
                    echo $db->lastErrorMsg();
                } else {

                }

                $sql2 = "UPDATE TeammateCurrent set Sunday='$day0', Monday='$day1', Tuesday='$day2', Wednesday='$day3', Thursday='$day4', Friday='$day5', Saturday='$day6' where uniqueID='$uniqueid';";

                $ret = $db->exec($sql2);
                if(!$ret){
                    echo $db->lastErrorMsg();
                } else {

                }
            }

        } else {
            echo "Query not successful";
        }

当上面的代码执行时,我收到错误Fatal error: Call to a member function fetchArray() on a non-object in /home/xxxx/public_html/xxxx.com/trg/rc2/db/startNewWeek.php on line 39

我在其他网页上运行了这样的代码并且工作正常,我在这里完全失去了。

我的桌子:

enter image description here

1 个答案:

答案 0 :(得分:3)

您正在重复使用变量$ret。您应该为SELECT语句和UPDATE设置不同的返回变量。在第二个循环中,您尝试执行返回UPDATE语句的fetchArray()