Use PHPMySQL to build a chat room-PHP source code

Source: Internet
Author: User
Ec (2); MySQL is a database software with excellent performance, and PHP is a powerful server-side scripting language. In the development of Shanxi Aluminum Factory website, the author uses PHP4.0MySQL3.23.38 to establish a variety of applications. Next, we will take a simple chat room design as an example to introduce the application of PHPMySQL in Web development. 1. Overall Design 1.1 conception and planning: the basic principle of the chat room is to store the speech data sent by each user connected to the same webpage in script ec (2); script

MySQL is a database software with excellent performance, and PHP is a powerful server-side scripting language. In the development of the Shanxi Aluminum Factory website, I used PHP4.0 MySQL3.23.38 to establish a variety of applications. Next, we will take a simple chat room design as an example to introduce the application of PHP MySQL in Web development.

1. Overall Design

1.1 conception and planning:

The basic principle of a chat room is to store the speech data transmitted by each user connected to the same webpage, and then transmit all the speech data to each user. That is to say, using a database to gather everyone's speeches and passing the data in the database to everyone realizes the chat room function.

1.2 Table Design

First, use MySQL to create a table chat to Store Users' speeches:

Mysql> create table chat
-> (Chtime DATATIME,
-> Nick CHAR (10) not null,
-> Words CHAR (150 ));

The table only sets three fields. The chtime is the time when the speaker speaks, nick is the nickname of the speaker, and words are the content of the speech. The speech can contain a maximum of 150 characters.

1.3 Webpage Design

A simple chat room usually requires two page boxes: one is the form in which the user inputs the speech, and the other is used to display the speech. Therefore, the code segment usually requires at least the following sections:

Create a page frame structure (main. php)

Show the program section (cdisplay. php)

Program section for sending user speeches (speak. php)

Log on to the chat room program section (login. php)

2. Code Design

After the above planning is complete, you can start code design. Using php, you can easily implement the above functions.

2.1 log on to login. php. The code in this section is a complete HTML webpage.



 User Logon

Enter your nickname


 
 



After the user submits his nickname, he enters the chat room. The following processing is handled by main. php.

Main. php:

Setcookie ("nick", $ nick) // uses cookies to record user nicknames. It is a common method for passing variables.
?>


Trial version of Shanxi Aluminum Plant chat room ver1.0




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.