Web Database Access from Desktop Applications
By Michael J. Ross2008-05-06
Sample Database
Most programming ideas are best taught through example, and this one is no exception. To demonstrate this technique, we will use a sample database, a desktop application, and a PHP script to connect the two together.
Continuing the aforesaid scenario, let's assume that when a prospect downloads your program, your Web site requires them to provide their name and e-mail address. The following SQL code will work for creating a simple but sufficient MySQL database, user, and table for storing the user data:
DROP DATABASE IF EXISTS product_database;
CREATE DATABASE product_database;
GRANT ALL ON product_database.* TO user@localhost IDENTIFIED BY 'password';
USE product_database;
DROP TABLE IF EXISTS product_registration;
CREATE TABLE product_registration (
registration_number INT UNSIGNED AUTO_INCREMENT PRIMARY KEY
,first_name VARCHAR(20) NOT NULL
,last_name VARCHAR(20) NOT NULL
,email_address VARCHAR(20) NOT NULL UNIQUE
,expiration_date DATE
);
INSERT INTO product_registration VALUES
( 1, 'John', 'Jones', 'john@example.com', '2008-05-01' )
,( 2, 'Jane', 'Smith', 'jane@example.com', '2008-05-30' )
;
To readers unfamiliar with SQL, a brief description of the code should suffice: Firstly, we create the database itself. Secondly, we create a new user with the name "user" and the password "password" (neither value of which you should use in any production database, for security reasons), with all privileges on the database. Thirdly, we create a new table for the product registration data. Lastly, we populate that new table with two sample records.
Tutorial Pages:
» Web Database Access from Desktop Applications
» Sample Database
» Database Access Script
» Desktop Application Access
» Database Updating
» Conclusion
