Playing an Audio or Video file stored in Mysql database- using PHP

by Selva 2008-03-13 12:56:04

We can store an audio or video file in Mysql database by using BLOB or MEDIUM BLOB or LARGE BLOB datatype.
We can fetch the audio or video file from database by using php code.We can also play the audio or video file in the browser.

Here is the sample code to explain this concept:

fetch.php
----------
header("Content-type: audio/mpeg");
$con=mysql_connect("localhost","root","rootpassword");
$db=mysql_select_db("db1");
$query="select song from musictable where sid=5";
$rs=mysql_query($query);
$song=mysql_result($rs,0,0);
echo $song;

play.html
---------
<html>
<body>
Hear The Song And Have Fun
<embed src="fech.php">
</body>
</html>

When you open play.html file in browser you can here a song that is stored in database.

Tagged in:

6198
like
2
dislike
0
mail
flag

You must LOGIN to add comments