Jump to content

Saving Audio to the database


___ROCK___

Recommended Posts

Hello I would like to know how do I store audio files in a database so I can retrieve them.

 

The problem starts when I try to save the audio file.  Right now I am using phpMyAdmin and manually inserting the data(which I intend to change later).

 

The problem occurs when I hit BROWSE and then OPEN.  It just loops and loops and then I get this error.  "#2006 - MySQL server has gone away"

 

So far this is my structure:

 

Table structure for table `music`
--

CREATE TABLE IF NOT EXISTS `music` (
  `music_id` tinyint(4) NOT NULL AUTO_INCREMENT,
  `music_title` varchar(200) DEFAULT NULL,
  `music_file` mediumblob,
  `music_catagory` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`music_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

 

 

and this is the code I am using to retrieve it.

 

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
{
// 6a.  Get the values with the new Array() $row[].
// Put the name of the field you want between the [] for $row.
echo "<br>ID: " . $row["music_id"];
echo "<br>Title: " . $row["music_title"];
echo "<br>Music Link: " . $row["music_file"];
echo "<br> Catagory: " . $row["music_catagory"];

echo "<br />";
echo "<br />";

}

 

 

If you can send me to a tutorial or help on how to save audio files and then retrieve them that would be very helpful.

 

Thanks In advance

Link to comment
Share on other sites

I am saving the audio file itself.

 

Yeah, well I wouldn't do that.

What  is the proper way to do this.  Can u show me an example. or how to do it.

 

You can't store an audio file in a database... only the directory path to where it resides on your server. ::)

 

We'll technically you could. Its just probably not the best idea.

Link to comment
Share on other sites

You can't store an audio file in a database... only the directory path to where it resides on your server. ::)

 

We'll technically you could. Its just probably not the best idea.

 

Interesting... learned something new today! 8) Like you said though, wouldn't want to do that for large/lots of files... I can already picture the access times.... :o

Link to comment
Share on other sites

i think it would be a waste of space also

i started doing images like that (Blob) then i got common sense

you start creating immensely huge tables, i think its simply simpler and a better idea to link a file using the following logic

here is an example of how i link

 

id is the file id

linked_id is the id of the table record that holds all the other data ( so i can link multiple images to one record )

filename is just the filename and not the path i set the path separately

 

CREATE TABLE IF NOT EXISTS `images` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `linked_id` int(11) NOT NULL,
  `filename` varchar(75) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `sc_income_id` (`linked_id`,`filename`),
  KEY `linked` (`linked_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.