Chat with us, powered by LiveChat A MySQL Database | Writedemy

A MySQL Database

A MySQL Database

Exercise 1

A rather more complex server as shown below would connect to a database. See for instance the form priceClient.html, which connects to priceClient.php and in turn to priceServer.php, which then reads from a mySQL database.

These files simulate a stockbroker’s site and by selecting one of the short codes, listed in the file priceClient.html you can get a static price quote.

The structure of the form is:

 

 

Web Services Demo

 

<body text=”#000000″ bgcolor=”#FFFFF0″ link=”#0000EE” vlink=”#551A8B” alink=”#FF0000″>

Share Price Query 

 

 

 

NAME=”queryForm”

ACTION=”stockClientlocal.php”

METHOD=”POST”

onSubmit=”return true”>

 

First Name

 

 

The web service has a selection of nominal share prices of a few companies in the London FTSE 100. These are identified by their shareCode; TSCO, BP, VOD, XTA, PSON.

If you type one of these codes into the query form, it will return the stored share price.

 

 

This simply asks the user to enter a shareCode, which it then sends by ‘POST’ to the client:

 

require_once(‘nusoap.php’); //loads the nusoap library

$client = new nusoap_client(‘http://localhost/priceServer.php’); //creates a new client connected to the server

$shareCode = $_POST[‘shareCode’]; //reads and stores the data send by the form

$sharePrice = $client->call(‘getSharePrice’,

array(‘param’ => ‘$shareCode ‘));

// the above lines call the getSharePrice function in the server using the data passed from the form

// they set a variable to the value of the call

 

echo $sharePrice; //Displays the sharePrice on the screen

echo “Request”;

echo “” . htmlspecialchars($client->request, ENT_QUOTES) . “”;

echo “Response”;

echo “” . htmlspecialchars($client->response, ENT_QUOTES) . “”;

// These last 4 lines display debug data and co-incidentally show the soap envelope

The structure of the server is:

 

function getSharePrice($param) {

mysql_connect(‘localhost’,’laureate_prof2′,’Password – TBA’); //connects to the database system,

//with user name and password

mysql_select_db(‘laureate_prof2’); //selects the specific database to use

$query = “SELECT sharePrice FROM sharePrices WHERE shareCode = ‘$param'”;

//passes SQL query to the database

$result = mysql_query($query); //executes the query and sets a variable to the result

$row = mysql_fetch_assoc($result); // selects the row as an array

return $row[‘sharePrice’]; // returns the value of the asked for parameter

}

require(‘nusoap.php’); //includes the nusoap library

$server = new soap_server(); //instantiates the nusoap server

//The following lines set up the WSDL, which we will discuss next week.

$server->configureWSDL(‘stockserver’, ‘urn:sharePrice’);

$server->register(“getSharePrice”,

array(‘param’ => ‘xsd:string’),

array(‘return’ => ‘xsd:decimal’),

‘urn:sharePrice’,

‘urn:sharePrice#getSharePrice’);

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)

? $HTTP_RAW_POST_DATA : ”;

$server->service($HTTP_RAW_POST_DATA);

?>

Summary

The client form accepts the user data and passes it on to the SOAP client, which creates a SOAP envelope, transmits the data to the server and receives the response.

It is the server which carries the functionality, connects to the database, runs the query and returns the data to the client.

However, this Web service returns a bare price without a company name and not even the short code originally entered.

The task

To improve this service to make the resultant display more user-friendly.

(Maybe add a title or comments to the bare number that is the current output, or perhaps display more information.)

 

Exercise 2

 

The task here is to improve the service still further and add more to the functionality so that the user can alter the price in the database or perhaps add extra company data. The database table was created by:

CREATE TABLE sharePrices (

stock_id int primary key,

shareCode CHAR( 5 ) ,

shareName CHAR( 10 ) ,

sharePrice DECIMAL(10,2) );

The data entered is:

INSERT INTO sharePrices VALUES (1,’TSCO’ , ‘Tesco’, 375.00);

INSERT INTO sharePrices VALUES (2,’BP’,’BP’, 460.00);

INSERT INTO sharePrices VALUES (3, ‘VOD’, ‘Vodafone’, 162.00);

INSERT INTO sharePrices VALUES (4, ‘XTA’, ‘Xstrata’, 1034.00);

INSERT INTO sharePrices VALUES (5, ‘PSON’, ‘Pearson’, 1134.00);

If you try to enter a duplicate stock_id, it will refuse.

Files needed for these exercises are included in attachment.

sharePricesClient.html

stockclientlocal.php

stockserverlocal.php

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order