如何使用PHP脚本和JSON从android在MySQL中插入BLOB数据类型?

时间:2014-02-05 15:09:49

标签: php android mysql json

我可以使用PHP和JSON在MySQL中插入android中的数据,但是现在我在保存BLOB类型时遇到了困难。

我确信PHP脚本工作正常,因为我使用硬编码数据测试它,并且文件在数据库中保存为BLOB。这是我的PHP方法:

 public function insertBlob($ReportFile,$ReportName,$DateCreated,$UserId){
        $blob = fopen($ReportFile,'rb');

        $sql = "INSERT INTO Reports (ReportFile,ReportName,DateCreated,UserId) VALUES(:ReportFile,:ReportName,:DateCreated,:UserId)";
        $stmt = $this->conn->prepare($sql);


        $stmt->bindParam(':ReportFile',$blob,PDO::PARAM_LOB);
      $stmt->bindParam(':ReportName',$ReportName);
       $stmt->bindParam(':DateCreated',$DateCreated);
        $stmt->bindParam(':UserId',$UserId);

        return $stmt->execute();
    }

然后我这样称呼这个方法:

insertBlob("$_POST[ReportFile]","$_POST[ReportName]","$_POST[DateCreated]","$_POST[UserId]");

如何将Android应用中的数据传递给PHP?

0 个答案:

没有答案