How do I insert into PDO (sqllite3)?

后端 未结 2 519
刺人心
刺人心 2021-02-05 20:30

I\'m having a bit of trouble inserting into a sqlite3 database with pdo. You\'ll have to excuse my ignorance with PDO, it seems so foreign coming from Python\'s database interfa

2条回答
  •  心在旅途
    2021-02-05 20:51

    You can have an error in your SQL query. You could print it and then try to execute it in some SQLite GUI interface like SQLite Database Browser.

    // you can skip PDO part for now, because we know it doesn't work
    // $dbh = new PDO('sqlite:vets.db');
    $query = "INSERT INTO vets(name,email,clinic,streetname,citystatezip,link,phone,fax,animal,region,visible) VALUES ($name,$email,$clinic,$streetname,$citystatezip,$link,$phone,$fax,$animal,$region,$visible)";
    echo $query;
    // $count = $dbh->exec($query);
    // $dbh = null;
    

    I see that you are not wrapping your values in quotes, probably that's the source of the problem. Maybe some typos in table field names as well. All will come out once you actually see the query.

提交回复
热议问题