title: Displaying BLOB image from database yii 2
body: <p>Hello I am using a table for the blob images that contains the images and a client column to reference it the question is how can I display an image blob based on the clientid so that I can show it in the webpage using yii 2?</p>
  
  <p>Here is a screenshot of the table.</p>
  
  <p><a href="https://i.stack.imgur.com/CO34p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CO34p.png" alt="enter image description here"></a></p>
  
  <p>Because in this particular article I got the impression it is only uploading the image as BLOB.
  <a href="https://stackoverflow.com/questions/27629478/yii2-display-image-stored-in-blob-database-field">Yii2 Display image stored in BLOB database field</a></p>
  
  <p>But how do I make it so that I would only returning/displaying the blob from the database?</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>I converted the answer into yii code.</p>
  
  <p>Controller</p>
  
  <pre><code>public function DisplayBlob($clientid){
        $model = new Slimages();
  
        return $model-&gt;DisplayBlob($clientid);
  
      }
  </code></pre>
  
  <p>Here is the model.php</p>
  
  <pre><code> public static function DisplayBlob($clientid){
      return static::find()-&gt;where(['clientid' =&gt; $clientid])-&gt;asArray()-&gt;all();
   //     $db = $db = mysqli_connect("localhost","root","","myenrollment"); //keep your database name
   //     $sql = "SELECT * FROM slimages WHERE clientid = $clientid"; // pass your clientid here
      // $statement = $db-&gt;query($sql);
      // $result = mysqli_fetch_array($statement);
      // return $result;
      //echo '&lt;img src="data:image/jpeg;base64,'.base64_encode($result['Picture'] ).'"/&gt;';
    }
  </code></pre>
  
  <p>View file</p>
  
  <pre><code> &lt;td colspan="2"&gt;&lt;?php 
              $result = SiteController::DisplayBlob($_user);
              foreach($result as $image){
               // echo  'hello';
                  echo '&lt;img src="data:image/jpeg;base64,'.base64_encode($image['Picture'] ).'" height="100" width="100"/&gt;';
              }
  
  
              ?&gt;&lt;/td&gt;
  </code></pre>