Reputation: 855
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());
}
Here is the error: Parse error: syntax error, unexpected 'insert' (T_STRING) in C:\xampp\htdocs\ExerciseFiles\Chap01\create.php on line 42
Upvotes: 0
Views: 166
Reputation: 1504
$db->sql_do("insert into $tn (animal, sound) values (?, ?), 'cat', 'Purr' "); //right here issues
should be
$db->sql_do("insert into $tn (animal, sound) values (?, ?)", 'cat', 'Purr');
look at the syntax highlighting.
Also it sounds like you don't understand how PHP works with strings, try this to see the difference:
$my_name = 'Matt';
echo 'Hello $my_name.';
echo "Hello $my_name.";
Upvotes: 1