2016-04-05 26 views
0

Bu kod, Cat ve Purr'u eklemeye çalıştığımda bana hata veriyor. Öğreticide çift tırnak işareti yoktu, ancak kodları da çalışmadı. Bu bir çeşit sözdizimi sorunu olmalı. Ayrıştırma hatası: sözdizimi hatası, beklenmedik 'uç' (T_STRING) C: Burada Sözdizimi hatası php ve sqlite ekleme deyimi

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()); 
} 

hata \ xampp \ htdocs \ ExerciseFiles \ Chap01 \ create.php hattında 42

+2

Sorunuzun Hatanızı ekleyiniz:

Ayrıca farkı görmek için bu deneyin, PHP dizeleri ile nasıl çalıştığını anlamıyorum gibi geliyor. –

+0

Ayrıştırma hatası: sözdizimi hatası, beklenmedik 'insert' (T_STRING) C: \ xampp \ htdocs \ ExerciseFiles \ Chap01 \ create.php satırında 42 – DDJ

cevap

1
$db->sql_do("insert into $tn (animal, sound) values (?, ?), 'cat', 'Purr' "); //right here issues 

dizim de

$db->sql_do("insert into $tn (animal, sound) values (?, ?)", 'cat', 'Purr'); 

bakmak olmalıdır.

$my_name = 'Matt'; 
echo 'Hello $my_name.'; 
echo "Hello $my_name."; 
+0

Çalıştı! Teşekkür ederim! – DDJ

+0

Endişelenme, neden işe yaradığını anlıyor musunuz? – mattumotu

+0

Evet, onu görüyorum. Öğreticiyi takdir ediyorum. '' = değişmez dize. "" komutlar ve dizeler için kullanılır. – DDJ

İlgili konular