Implement the Ajax client and server layer

Source: Internet
Author: User
Tags php database ibm developerworks
Ajax (Asynchronous JavaScript + XML) is rapidly becoming a fashionable technology that can be used for Web applications running in browsers. Program Provides desktop-quality software features ...... This article describes some of the development banking scenarios. Specifically, a backend database will be created using the MySQL database. We will study several MySQL command line tools, use these tools to connect to the database, create, define, and populate the database-related data. Then, develop a middle-layer PHP module to provide the banking business logic. This module uses ODBC to connect to the MySQL database. Finally, a bank portal is developed to allow users to interact with this end-to-end application through this simple browser user interface. This application will soon be able to run on Zend core.

Introduction

This banking scenario mainly provides basic services for bank cashier execution. Customer data is an important part of this scenario. After that, you can use the ODBC MySQL driver provided by Zend core to obtain and update stored customer data. After the customer data is processed, the focus is on the core banking logic required to provide the bank cashier function. We developed a PHPCodeModule to provide the core banking logic and Use ODBC for necessary database access. The main advantage of using Zend core and PHP to implement banking logic is that the built-in MySQL support can be used.

After the database is created and the PHP module is developed, the bank cashier is provided with a user interface that executes four core functions. We use a thin client to access the core banking logic encapsulated in the PHP module. Specifically, this web-based thin client is generated in the Ajax style: XHTML, Cascading Style Sheet (CSS), JavaScript, and XMLHttpRequest (xhr ). It provides a simple user interface for bank cashier to execute core banking functions. This browser user interface also demonstrates how the browser client logic communicates with the server PHP logic over the network.

By the end of this article, we will build a database, a PHP module that provides core banking logic, and a single-page browser user interface, which are part of the banking scenario.

MySQL database

MySQL is an open source database. In our scenariosCommunityServer version, which is a compact database server with many useful features. Because the implementation of this banking scenario is based on open source products, MySQL and Zend core PHP are suitable combinations. Zend core supports MySQL and a variety of tools supporting MySQL management and programming. In our scenario, only the MySQL command line client is used to manage MySQL. We will use the MySQL database to create a bank account database for this scenario.

Create and fill in the Bank Database

In this scenario, the following account information is stored for a given customer:

    • Accountholdername
    • Accountnumber
    • Checkingbalance
    • Stockname
    • Stockquantity
    • Stockvalue

The account information of a given customer includes the account holder's name, account number, current asset balance, number of one stock owned by the customer, total number of owned shares, and current market value of the stock portfolio. The following sections detail how to create a database table, and then fill the table with the account information of some fictitious bank customers. Let's get started!

Follow these steps to create a database and then fill the table with application-related data:

  • If eclipse is not running, start it (C: \ eclipse \ eclipse.exe ).
  • Make sure that the PHP perspective is enabled in Eclipse:
    • Choose WINDOW> open perspective> Other> PHP and click OK.
  • In eclipse, choose File> New> project.
  • Select General> project and click Next.
  • Enter bankdb in the Project Name field.
  • Click Finish.
  • Right-click the bankdb project and choose new> Other.
  • Select general-> file and click Next.
  • In the file name field, enter bankdb. SQL and click Finish.
  • Enter or paste the code in Listing 1 as the bankdb. SQL content.
  • Save and close the file.
  • To start the MySQL command line client, choose Windows Start Menu> All Programs> mysql> MySQL Server> MySQL command line client.
  • In the MySQL command line window, enter the password webtech and press Enter.
  • At the mysql> prompt, enter source c: \ eclipse \ workspace \ bankdb. SQL and press Enter.
  • Check whether the bankdb database exists to confirm that the preceding command has been correctly executed. The command used for checking is as follows:
    • Show databases;
    • Use bankdb;
    • Show tables;
    • Describe account;
  • In the MySQL command line client, enter exit to close it.

Listing 1. bankdb. SQL File Content

-- This file is part of the end-to-end Ajax development article in
-- The IBM developerworks. This file contains a simple dB script
-- Create a database and populate it with the data.
--
-- Last modified: May/10/2007.
--
-- To execute the following statements in MySQL, do the following steps.
-- 1) Start MySQL command line client.
-- 2) enter your MySQL admin password.
-- 3) type the following line by substituting <your_ SQL _file_dir> with
-- Directory name where the file is stored.
-- Source <your_ SQL _file_dir> \ bankdb. SQL

--
-- Table structure for table 'bankdb'
--

Drop database bankdb;

Create Database bankdb;

Use bankdb;

Create Table account (
Accountholdername varchar (20) not null,
Accountnumber integer not null,
Checkingbalance double not null,
Stockname varchar (6 ),
Stockquantity integer,
Stockvalue double,
Primary Key (accountholdername, accountnumber)
);

--
-- Populating data for table 'account'
--

Insert into account values ('frodo ', 435245,234 4.45, 'goog', 100,345 3.32 );
Insert into account values ('Sam ', 928462,758 3.32, 'csco', 200,532 3.43 );
Insert into account values ('pippin ', 234233,344 4.62, 'intc', 300,421 3.76 );
Insert into account values ('merry', 642445,100 5.32, 'msft ', 250,135 3.32 );
Insert into account values ('aragorn', 972321,642 4.24, 'hpq', 525,120 43.94 );
Insert into account values ('gandalf', 432134,539 2.23, 'ibm, 400,100 43.78 );
Insert into account values ('legolas ', 590134,431 3.82, 'Dell', 325,592 6.62 );

Use PHP to access the MySQL database

One of the most popular features of PHP is that it provides simple and outstanding support for accessing data from different manufacturers' databases, including MySQL. It provides a simple and effective way to integrate business logic and databases. In the past few years, the PHP community has completed several improvements, such as PHP Data Objects (PDO). PDO provides an abstraction layer, no matter which database server is used, this abstraction layer exposes the same API functions. There are two styles of PHP database API functions: Procedural and object-oriented. In this scenario, we use the direct database API for MySQL to get a basic understanding. PHP provides two methods to access MYSQL:

    • MySQL
    • MySQL improved

......

Related Article

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.