PHP Post-Method prepare()返回False

时间:2017-03-29 19:34:10

标签: php sql sqlite slim

这是问题,我想为我的Web服务创建一个Post-Method。我使用PHP7和SQLite3数据库创建了Slim Framework。我实现了以下代码:

$app->post('/api/generalinformation', function ($request) {


   try {
       $db = new PDO("sqlite:D:/Schule/notfunk_app/IPNF.db") or die("Cannot open Database");

       $query = "insert into nlv_GeneralInformation (SystemID, InformationID, Title, Description, Importance) values (:SystemID, :InformationID, :Title, :Description, :Importance);";
       $stmt = $db->prepare($query);

       if($stmt === false){
          die("prepare() failed");
       }
       $SystemID = $request->getparsedBody()["SystemID"];
       $InformationID = $request->getparsedBody()["InformationID"];
       $Title = $request->getparsedBody()["Title"];
       $Description = $request->getparsedBody()["Description"];
       $Importance = $request->getparsedBody()["Importance"];

       $stmt->bindParam(":SystemID", $SystemID, PDO::PARAM_INT);
       $stmt->bindParam(":InformationID", $InformationID, PDO::PARAM_INT);
       $stmt->bindParam(":Title", $Title, PDO::PARAM_STR);
       $stmt->bindParam(":Description", $Description, PDO::PARAM_STR);
       $stmt->bindParam(":Importance", $Importance, PDO::PARAM_INT);

       $stmt->execute();

       $db = null;
   } catch (PDOException $e) {
       echo $e->getMessage();
   }
});

但是prepare()funktion总是让我失意。我测试了查询并且它有效。

0 个答案:

没有答案