___ROCK___ Posted December 20, 2009 Share Posted December 20, 2009 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 Quote Link to comment Share on other sites More sharing options...
trq Posted December 20, 2009 Share Posted December 20, 2009 What exactly are you storing in the music_file field? I would make music_file a varchar and simply store the path to your file. Quote Link to comment Share on other sites More sharing options...
___ROCK___ Posted December 20, 2009 Author Share Posted December 20, 2009 What exactly are you storing in the music_file field? I would make music_file a varchar and simply store the path to your file. I am saving the audio file itself. But I plan to have many audio files there. Quote Link to comment Share on other sites More sharing options...
trq Posted December 20, 2009 Share Posted December 20, 2009 I am saving the audio file itself. Yeah, well I wouldn't do that. Quote Link to comment Share on other sites More sharing options...
___ROCK___ Posted December 20, 2009 Author Share Posted December 20, 2009 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. Quote Link to comment Share on other sites More sharing options...
trq Posted December 21, 2009 Share Posted December 21, 2009 As I already said. Save the path to your file within the database. Quote Link to comment Share on other sites More sharing options...
___ROCK___ Posted December 21, 2009 Author Share Posted December 21, 2009 question can you show me the syntax for the path. Quote Link to comment Share on other sites More sharing options...
trq Posted December 21, 2009 Share Posted December 21, 2009 I'm not sure I understand where /how your stuck. Say you have an mp3 within mp3s/foo.mp3 all you do is store mp3s/foo.mp3 within your database. You can then use this path to access the file. Quote Link to comment Share on other sites More sharing options...
bacarudaguy Posted December 22, 2009 Share Posted December 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
bacarudaguy Posted December 22, 2009 Share Posted December 22, 2009 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! Like you said though, wouldn't want to do that for large/lots of files... I can already picture the access times.... Quote Link to comment Share on other sites More sharing options...
gevensen Posted December 22, 2009 Share Posted December 22, 2009 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 ; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.