Jump to content

Database or TXT File


gaza165

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?
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;
}

 

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.