title: Display BLOB data from SQLITE database using PHP
body: <p>Hope You all have a Great Day, I new with <code>SQLITE</code> DB and so I'm little confused about handling BLOB data.I tried lot of things ,but nothing get in to favor of me.</p>
  
  <p><strong>Here is My Code</strong></p>
  
  <p><strong><em>INSERTING DATA</em></strong></p>
  
  <blockquote>
    <p>insert.php</p>
  </blockquote>
  
  <pre><code>&lt;form method="POST" enctype="multipart/form-data"&gt;
          model no:&lt;input type="text" name="model_no"\&gt;&lt;span style="color: red"&gt;&lt;?php echo $messages["model_no"]; ?&gt;&lt;/span&gt;
          image:&lt;input type="file" name="image" id="image"\&gt;&lt;span style="color: red"&gt;
          &lt;input type="submit" value="save" id="save" name="save"/&gt;
          &lt;input type="reset" value="Clear"/&gt;
      &lt;/form&gt;
  </code></pre>
  
  <blockquote>
    <p>include.php</p>
  </blockquote>
  
  <pre><code>&lt;?php
      $flag = 0;
      class MyDB extends SQLite3
      {
          function __construct()
          {
              $this-&gt;open('../database.db');
          }
      }
  
      //checking save button is clicked
      if(isset($_POST["save"])){
          $model_no = $_POST['model_no'];
          $image = $_FILES['image']['name'];
  
          if($model_no != '' &amp;&amp; $image != ''){
              $flag = 1;
          }
  
          if($flag == '1'){
              $db = new MyDB();
  
              if(!$db){
                  echo $db-&gt;lastErrorMsg();
              } 
              else{
                      $dbb = new MyDB();
  
                      $sql = 'SELECT COUNT(*) as count FROM fisfis WHERE model_no =  "'.$model_no.'"';
  
                      //echo $sql;
  
                      $rows = $dbb-&gt;query($sql);
                      $row = $rows-&gt;fetchArray();
                      $numRows = $row['count'];
                      //echo $numRows;
  
                      if($numRows != 0){
                          $flag = 0;
                          echo "error:this model no is already taken";
                      }else{
                          $sqlp = "INSERT INTO fisfis(model_no, image) values('$model_no','$image')";
  
                          if($dbb-&gt;exec($sqlp)){
                              echo "data inserted successfully\n";
                          }
                          else{
                              echo"error:\n";
                              echo "data not inserted \n";
                              echo"contact admin for details\n";
                          }
                      }
  
             }
          }
          else{
                          echo"error:\n";
                          echo "data not inserted : data fields cannot be empty\n";
              }
  
      }   
  ?&gt;
  </code></pre>
  
  <p>this is very successfully inserting data in to my table (table name:fisfis)</p>
  
  <p><strong><em>DISPLAYING DATA</em></strong></p>
  
  <blockquote>
    <p>display.php</p>
  </blockquote>
  
  <pre><code>&lt;form method="POST" enctype="multipart/form-data"&gt;
          &lt;p&gt;Enter Barcode : &lt;input type="text" name="search_model" id="search_model" /&gt;&lt;/p&gt; 
          &lt;!--&lt;p&gt;&lt;img src='image.php?id=&lt;?php //echo $row['model_no'];?&gt;'/&gt;&lt;/p&gt;--&gt;
          &lt;p&gt;&lt;input type="submit" value="search" name="search" id="search"/&gt;&lt;/p&gt;
      &lt;/form&gt;
  </code></pre>
  
  <blockquote>
    <p>display_include.php</p>
  </blockquote>
  
  <pre><code>&lt;?php
  
      $flag2 = 0;
      $flag3 = 0;
  
      class MyDB extends SQLite3
      {
          function __construct()
          {
              $this-&gt;open('../database.db');
          }
      }
  
      $db = new MyDB();
  
      if(isset($_POST["search"])){
          $model_no = '';
          $model_no = $_POST['search_model'];
  
          if($model_no != ''){
              $flag2 = 1;
          }
  
          if($flag2 == '1'){
              $db = new MyDB();
  
              if(!$db){
                  echo $db-&gt;lastErrorMsg();
              } 
  
              else{
                  $dbb = new MyDB();
  
                  $sql = 'SELECT COUNT(*) as count FROM fisfis WHERE model_no =  "'.$model_no.'"';
  
                  $rows = $dbb-&gt;query($sql);
                  $row = $rows-&gt;fetchArray();
                  $numRows = $row['count'];
                  echo $numRows;
  
                  if($numRows == 0){
                      echo 'sorry this model no is not exists';
                      echo '&lt;br/&gt;';
                      echo '&lt;a href="insert_controller.php"&gt;create new&lt;/a&gt;';
                      $flag2 = 1;
                  }else{
                      echo "this is exisists";
                      $flag3 = 1;
                  }
  
                  if($flag3 == 1){
                      $sqla = 'SELECT * FROM fisfis WHERE model_no =  "'.$model_no.'"';
                      $result = $dbb-&gt;query($sqla);
  
                      while($row = $result-&gt;fetchArray(SQLITE3_ASSOC) ) {
  
                          echo "MODEL NO = ". $row['model_no'] ."\n";
  
                          $img = '\'&lt;img src="'. $row['image'] .'" width="100" height="100"/&gt;\'';
                          echo $img;
  
                     }
  
                  }
  
              }
  
          }
      }
  
  
  ?&gt;
  </code></pre>
  
  <p>the display part displaying all data other than blob ,what i have tried</p>
  
  <p>1.try to echo the image inside the php script</p>
  
  <pre><code>$img = '\'&lt;img src="'. $row['image'] .'" width="100" height="100"/&gt;\'';
  </code></pre>
  
  <ol start="2">
  <li><p>try to display image inside html tag</p>
  
  <p></p></li>
  </ol>
  
  <p>but this is not working,please help me to fix this,thanks in advance</p>