Home arrow XML arrow Building an AJAX-Based Chat: Interacting With a Database
XML

Building an AJAX-Based Chat: Interacting With a Database


In this third and final part of a tutorial that explains how to build an AJAX-based chat application, Alejandro Gervasio covers creating the PHP files that directly interact with a MySQL database, adding and fetching chat messages. He also makes some suggestions for expanding the functions of the application.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 50
November 21, 2005
TABLE OF CONTENTS:
  1. · Building an AJAX-Based Chat: Interacting With a Database
  2. · Adding messages to the database: looking at the “sendchatdata.php” file
  3. · Reading messages from the server: defining the “getchatdata.php” file
  4. · Putting the files together: the complete chat application at a glance

print this article
SEARCH DEVARTICLES

Building an AJAX-Based Chat: Interacting With a Database
(Page 1 of 4 )


A downloadable file for this article is available here.

 Here we are again. This is the concluding part of the series “Building an AJAX-based chat.” Welcome back. As you probably remember, developing an extensible chat application by using AJAX is not only a fairly easy task, but it’s also a fun experience. Stripped down to its bare bones, I implemented the driving logic of the chat by splitting the whole application into two different pieces of code. These are the “sender” and “receiver” modules respectively, which utilized two requester objects in order to handle independently http requests, for inserting new comments into the database and fetching chat messages.

Stepping back briefly to the previous part of the series, I coded all the JavaScript functions that made up the “receiver” module, as well as some additional functions aimed at building the basic layout of the chat page. Also, in order to illustrate with a clear example how the chat application was capable of registering user’s nicknames, I went through the development of a basic login page. This page implemented a simple PHP session mechanism for storing nicknames during the complete chat session.

Considering that the AJAX-based program is near to completion, the question is: what is next? Remember that from the very beginning of this series, I paid strong attention to writing all the code that runs on the browser, oriented to working with requester's objects, along with some simple PHP snippets. However, as you may have noticed, I didn’t get my hands into the complexities of creating the PHP files that directly interact with a MySQL database, handy for adding and fetching chat messages. Since I purposely left “untouched” the server PHP scripts for last, in this final article, I’ll code the required PHP files for accessing the database and handling messages.

Before I leap into writing down the PHP code, a brief clarification is in order: I’ll use a MySQL wrapping class for accessing the mentioned database, so all the sample files will use this class for running SQL queries and handling result sets. However, as you’ll see shortly, the code is flexible enough to be changed to work with a procedural method, in case you’re not familiar with an object-oriented approximation.

Having drawn the guidelines for this final tutorial, let’s get rid of the irrelevant details and start writing the server code for the chat application. Let’s go!


blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials

antalya escort escort antalya antalya escortlari antalya escort bayan