How to Save Images and Videos In A Database Like MySQL for PHP, Microsoft SQL Server For ASP.Net and Other Programming Languages like C# .Net, VB .Net, etc.

If we use this option to save Images and Videos instead of their file paths in the server where they are actually saved will lead to high level of security because then we can use various encryption methods apart from the encryption options given by the Database (Server) itself.

Using encryption methods like this even if the web server or data center server gets hacked the files if videos of images if encrypted using databases like MySQL and MS SQL Server and Oracle, the chances of getting the information leaked gets highly less because even if the database file gets stolen or leaked or hacked the encyotion keys or methods will not let it get open.

The encryption methods used should be designed and kept on a different server or a stand alone pc may be where the web system is being designed.

For Example in MySQL we can use LONGBLOB field type for that particular Table created in the MySQL Database.

For Example,

Table Creation SQL Script:-


SQL Statement For Insert Video In MySQL Table named as media:-

INSERT INTO media values ('File_Name',LOAD_FILE("C:\\Users\\Public\\Videos\\Sample Video\\ao.mp4"));

insert into media(GAME_ID,name,VIDEO) values (1,'testVideoUploadInDB', load_file('C:\Users\Mohsin\Videos\Any Video Converter\Youtube\testvideo.mp4'))

insert into media(GAME_ID,name,VIDEO) values (2,'testVideoUploadInDB', load_file('C:\Users\Mohsin\Desktop\testvideofile.mp4'))

PHP Code:-

$sql = "insert into media(GAME_ID,name,VIDEO) values (1,\'testVideoUploadInDB\', load_file(\'C:\\Users\\Mohsin\\Videos\\Any Video Converter\\Youtube\\testvideo.mp4\'))\n" . "";

For Fetching Video From Database:-

$query1=mysql_query("SELECT * FROM media where GAME_ID=2"); while($qry1=mysql_fetch_array($query1)) { $vid=$qry1['VIDEO'];

echo $query1;

For Detalis on storing Images and Videos in Microsoft SQL Server Database kindly click on the following link:-

Table Encryption is yet to study by me if the option is available in the databases but putting encryption of such type needs a internet connection with a very high speed, I mean atleast 30 MBps will be needed to use or to fetch data from database quickly from the database using such security techniques which includes database passwords.

Best Regards,

For any type of Inquiry and orders, kindly write to us at

About Our Team at AL-Kahaf Technologies Inc.