IT Community - Software Programming, Web Development and Technical Support

How do I store binary data in mysql?

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...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-20-2007, 08:50 AM
sivaramakrishnan sivaramakrishnan is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 74
sivaramakrishnan is on a distinguished road
Post How do I store binary data in mysql?

Hi,

How do I store binary data in mysql?

Thanks
sivaraman
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-11-2007, 04:48 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: How do I store binary data in mysql?

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 02:38 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0