Call to a member function fetch_field() on a non-object MySQLiDB



PHP Snippet 1:

$sql = "INSERT INTO table1 (field1,field2,field3) VALUES (?s,?s,?s) 
        ON DUPLICATE KEY UPDATE field2=VALUES(field2),field3=VALUES(field3)";
$db->query($sql, $value[$i]['value1'],$value[$i]['value2'],$value[$i]['value3']);

PHP Snippet 2:

foreach ($value as $row)
{
    $sql = "INSERT INTO table1 SET ?u
            ON DUPLICATE KEY UPDATE field2=VALUES(field2),field3=VALUES(field3)";
    $db->query($sql, $row);
}

PHP Snippet 3:

$ins = array();
foreach ($value as $row) {
    $ins[] = $db->parse("(?s,?s,?s)",$row['value1'],$row['value2'],$row['value3']);
}
$instr = implode(",",$ins);
$sql = "INSERT INTO table1 (field1,field2,field3) VALUES ?p 
        ON DUPLICATE KEY UPDATE field2=VALUES(field2),field3=VALUES(field3)";
$db->query($sql, $ins);