gaza165 Posted June 25, 2009 Share Posted June 25, 2009 Hi guys, Is it quicker to insert and retrieve into a txt file on the server than it is making a connection to a database?? Im trying to write a chat program and was wondering if it was quicker to store the data in a txt file or into a database?? thanks Garry Quote Link to comment https://forums.phpfreaks.com/topic/163660-database-or-txt-file/ Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 DATABASE Quote Link to comment https://forums.phpfreaks.com/topic/163660-database-or-txt-file/#findComment-863504 Share on other sites More sharing options...
gaza165 Posted June 25, 2009 Author Share Posted June 25, 2009 Im going for speedy message posting and message retrieval... is a txt file not a good idea? Quote Link to comment https://forums.phpfreaks.com/topic/163660-database-or-txt-file/#findComment-863509 Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 There are so many more advantages of using a MySQL database over a txt file-storage system. First off it will be faster. Second off I'm sure you're going to want to limit chat displayed, that's much easier with MySQL. Google 'MySql vs text file' you'll find tons of reasons to use a database over a text file. Quote Link to comment https://forums.phpfreaks.com/topic/163660-database-or-txt-file/#findComment-863514 Share on other sites More sharing options...
gaza165 Posted June 25, 2009 Author Share Posted June 25, 2009 The problem i find with using a database is that because im making constant connections to retrieve the last message, it is often slow and glitches because of the amount of connections it has to make each time. Quote Link to comment https://forums.phpfreaks.com/topic/163660-database-or-txt-file/#findComment-863518 Share on other sites More sharing options...
Alex Posted June 25, 2009 Share Posted June 25, 2009 What other language are you using to make it besides php/mysql? I made a 'chat box' using Ajax/Php/MySQL, if it's done efficiently and correctly there shouldn't be any issues. Quote Link to comment https://forums.phpfreaks.com/topic/163660-database-or-txt-file/#findComment-863522 Share on other sites More sharing options...
gaza165 Posted June 25, 2009 Author Share Posted June 25, 2009 I have done the same... used Ajax/JQuery/PHP http://myshoutbox.thedesignmonkeys.co.uk Quote Link to comment https://forums.phpfreaks.com/topic/163660-database-or-txt-file/#findComment-863525 Share on other sites More sharing options...
gaza165 Posted June 25, 2009 Author Share Posted June 25, 2009 <? include ('dbconnect.php'); include_once "init.inc.php"; require_once 'HTML/BBCodeParser.php'; $parser = new HTML_BBCodeParser(parse_ini_file('BBCodeParser.ini')); $lastid = $_GET['lastid']; $nick = $_GET['nick']; $message = mysql_query("SELECT * FROM chat WHERE chat_id > '$lastid'") or die(mysql_error()); $maxid = mysql_query("SELECT MAX(chat_id) FROM chat"); $lastid = mysql_fetch_row($maxid); $lastid = $lastid[0]; if(mysql_num_rows($message) == 0) { $norecords = "No Posts As Yet"; } while ($row = mysql_fetch_array($message)) { $body = $row['message']; $body = str_replace('','<img src="img/smilies/485.png" width="15px" height="15px" class="icon">',$body); $body = str_replace('','<img src="img/smilies/486.png" width="15px" height="15px" class="icon">',$body); $body = str_replace('','<img src="img/smilies/363.png" width="15px" height="15px" class="icon">',$body); $body = str_replace(':S','<img src="img/smilies/286.gif" width="15px" height="15px" class="icon">',$body); $data = array('id'=>$row['chat_id'] , 'name'=>$row['nick'], 'message'=>$parser->qParse($body),'time'=>date("H:i:s",strtotime($row['timestamp']))); } $json = '{"latest":"'.$lastid.'","noofposts":"'.$postrow[0].'", "response":['; $json .= json_encode($data); $json .= ']}'; echo $json; ?> function Get_Message() { $.getJSON("action/getmessages.php?lastid=" + id + "&nick=" + $("#name").val() + "&room_name=" + $('#room-select :selected').text(), function(json){ id = json.latest; $(".noofposts").html(json.noofposts); $.each(json.response, function (i, item){ $("ul.shoutbox").append( "<li><h4>" + item.time + "</h4><h2>" + item.name + ": </h2><p class='word-wrap'>" + item.message + "</p></li>" ); }); }); var objDiv = document.getElementById("scroll"); objDiv.scrollTop = objDiv.scrollHeight; } Quote Link to comment https://forums.phpfreaks.com/topic/163660-database-or-txt-file/#findComment-863535 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.