mardi 5 avril 2016

Syntax issue with php and a sqlite insert statement

This code gives me an error when I try to insert Cat and Purr. The tutorial didn't have a double quotation mark, but their code didn't work either. This has to be a syntax issue of some sort.

message('creating the db Object');
    $db = new bwSQLite3(DB_FILENAME, TABLE_NAME);
    $tn = TABLE_NAME;
    message('creating the table');
    $db->sql_do("Drop table if exists $tn");
    $db->sql_do("create table $tn ( id integer primary key, animal text, sound text )");
    //insert some records
    $db->sql_do("insert into $tn (animal, sound) values (?, ?), 'cat', 'Purr' "); //right here issues
    $db->sql_do("insert into $tn (animal, sound) values (?, ?), 'dog', 'Woof' ");
    $db->sql_do("insert into $tn (animal, sound) values (?, ?), 'duck', 'Quack' ");
    $db->sql_do("insert into $tn (animal, sound) values (?, ?), 'bear', 'Grr' ");
    message('there are %d rows in the table', $db->count_recs());
}catch (PDOException $e) {
    error($e->getMessage());
}

Aucun commentaire:

Enregistrer un commentaire