1

I'm working with SQLite on my webserver and have had no problems until now.

        $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";
        }

When the code above executes, I get the error 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

I've ran code just like this on other pages and they work fine, I'm at a total loss here.

My tables:

enter image description here

10
  • 1
    If you run the select in the sqlite command line does it work? Commented Jun 20, 2016 at 12:57
  • @Apokryfos I'm not sure how to do that, is it possible on a remote server? Commented Jun 20, 2016 at 12:58
  • @Saty that is part of the documentation @ tutorialspoint.com/sqlite/sqlite_php.htm I did try however, and did not work still. Commented Jun 20, 2016 at 12:59
  • If the remote server allows SSH connections and has the sqlite3 CLI (or similar) installed you can just remote in and do something like : sqlite3 dbname.db "query" Commented Jun 20, 2016 at 13:00
  • @apokryfos I don't think I have access to ssh in my current project Commented Jun 20, 2016 at 13:01

1 Answer 1

3

you're reusing the variable $ret. You should have a different return variable for the SELECT statment and UPDATEs. In the second loop you're trying to do a fetchArray() of the return of an UPDATE statement.

Sign up to request clarification or add additional context in comments.

4 Comments

Fatal error: Call to undefined method SQLite3Result::lastErrorMsg() in
sorry I meant print_r($db->lastErrorMsg()); die();
If I uncomment out the echo'd string in my while statement, it appears it gets through a single iteration and then throws the error mentioned in my post.
Ahh.. yes because you're reusing the variable $ret. You should have a different return variable for the SELECT statment and UPDATEs. In the second loop you're trying to do a fetchArray() of the return of an UPDATE statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.