This is a discussion on How do I store binary data in mysql? within the PHP Programming forums, part of the Web Development category; Hi, How do I store binary data in mysql? Thanks sivaraman...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| hey, After surfing i got few information about the binary data in mysql... Binary data can be stored in a MySQL database in a BLOB field. A BLOB is a binary large object that can hold a variable amount of data. This essentially means that BLOB is a datatype that can hold binary content, and we can use it to store files. For Example: Creating a Sample Table: We will name the table as 'binary_data_files' which will hold Binary Data. CREATE TABLE binary_data_files (file_id tinyint(3) unsigned NOT NULL auto_increment, bin_data mediumblob NOT NULL, description tinytext NOT NULL, filename varchar(50) NOT NULL, filesize varchar(50) NOT NULL, filetype varchar(50) NOT NULL, PRIMARY KEY (file_id)); below is the sample code <?php $db = mysql_connect("localhost", "root",""); mysql_select_db("mybuddy",$db); //connects to our mybuddy database //replace the above two string's with your database specific values if (isset($binary_File) && $binary_File != "none") { $data = addslashes(fread(fopen($binary_File, "r"), filesize($binary_File))); $strDescription = addslashes($file_description); $sql = "INSERT INTO binary_data_files "; $sql .= "(description, bin_data, filename, filesize, filetype) "; $sql .= "VALUES ('$strDescription', '$data', "; $sql .= "'$binary_File_name', '$binary_File_size', '$binary_File_type')"; $result = mysql_query($sql, $db); echo "<font face=verdana size=2>The file was successfully added to our database.<P>"; echo "<P><B>File Name: </B>". $binary_File_name; echo "<P><B>File Size: </B>". $binary_File_size ." bytes (approx ". $binary_File_size/1024) ." KB)"; echo "<P><B>File Type: </B>". $binary_File_type; } mysql_close(); ?> </font> try this code.....
__________________ Venkat knowledge is Power |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is Binary Portability Testing? | simplesabita | Software Testing | 1 | 11-13-2007 04:36 AM |
| How do we import or export data in MySql | Jeyaseelansarc | Database Support | 8 | 08-17-2007 07:25 AM |
| how to store and retrieve data from cookies | hanusoftware | ASP and ASP.NET Programming | 1 | 08-09-2007 07:17 AM |
| Development using Binary? | prasannavigneshr | Technology BUZZzzzzz | 12 | 08-06-2007 10:11 AM |
| Encrypting data in mysql | eric | PHP Programming | 2 | 07-30-2007 06:08 AM |