GrumpyCrouton GrumpyCrouton - 1 year ago 128
PHP Question

fetchArray() not working in SQLite

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);
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);
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/ 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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download