Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am able to insert data from android in MySQL using PHP and JSON, but now I have a difficulty when saving a BLOB type.

I am sure that the PHP script is working fine as I tested it using hardcoded data and the file is saved as BLOB in the database. This is my PHP method:

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

Then I am calling this method like this:

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

How can I pass data from my Android app to PHP?

share|improve this question
    
How are you getting the physical reportfile to the server?? –  user574632 Feb 5 at 15:12
    
First I am storing the files selected from my android app to a remote server then I want those files stored in MySQL database which the database is also on the same server. If I enter an existing file as hard-coded instead of "$_POST[ReportFile]"...it works but obviously now I want to pass the file from my android app. –  cloe Feb 5 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.