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
https://forums.phpfreaks.com/topic/185822-saving-audio-to-the-database/
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. ::)

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.

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

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 ;

Archived

This topic is now archived and is closed to further replies.

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