PHP SQL blob video

PHP SQL blob video

code php ini untuk membuat video blob dari database SQL.

Kenapa harus blob?

Supaya tidak mudah di download, itu salah satunya yang saya tau. website berita biasanya alamat videonya pada pake blob, streaming juga pake blob.

Coding dibawah ini hanya contoh, untuk kawan-kawan belajar dan kembangkan

Code php 1

<?php
  echo 'h';
    $arr=array();
    $con=mysql_connect('localhost','root','46');
  mysql_select_db('test',$con);
    $query="select video from test2";
    $result=mysql_query($query,$con);
    $arr=mysql_fetch_array($result);
  header('content-type: video/mp4'); 
  echo $arr[0];
?>

Code php 2

<?php
mysql_connect('localhost', 'root', '46') or die('Could not connect to MySQL server');
mysql_select_db('test') or die('Could not select database');

if (($result = mysql_query('SELECT video FROM test2')) !== false) {
    header('Content-Type: video/mp4'); 
    print mysql_result($result, 0);
} else {
    // actions to take if it fails
}

?>

Code php 3

<?php
$db = new PDO('mysql:host=127.0.0.1;dbname=test', 'root', '46');

if (($result = $db->query('SELECT video FROM test2')) !== false) {
    header('Content-Type: video/mp4');
    print $result->fetch(PDO::FETCH_COLUMN);
} else {
    // actions to take if it fails
}
?>

Code php 4

<?php

function displayvideo(){
    global $db_user, $db_password, $media_db_name, $db_host;
    $video = "some_video.mp4";
    $dbconnect = 'mysql:dbname='.$media_db_name.';host='.$db_host.'';
    try {
        $db = new PDO($dbconnect, $db_user, $db_password);
    } catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
    }
    if (($result = $db->query('SELECT video FROM videos WHERE `name` = "'.$video.'"')) !== false) {
        echo '<div content="Content-Type: video/mp4">
                  <video width="700" height="450" controls="controls" poster="image" preload="metadata">
                  <source src="data:video/mp4;base64,'.base64_encode($result->fetch(PDO::FETCH_COLUMN)).'"/>;
              </video>
          </div>';
    } else {
        // actions to take if it fails
    }
}

?>


Sumber: stackoverflow.com

Komentar