crazyweblist.com crazyweblist.com
   Main About Us Privacy of Info Terms of Use Add Url Add Article
Search:   
 
 

Batteries Are Affected By Temperature

Batteries are affected by temperature and or humidity. If batteries are too hot or too cold, then ye ... - Dan Hagopian
 

Removing Incoming Email in MS Exchange, C# Example

The purpose of one of our projects was MS Exchange handler for processing incoming email. - Boris Makushkin
 

Computer Training; Your Gateway to the Competitive IT World!

Computers have been long since introduced among mankind; and it was not so long after people adopted ... - Thomas DeReyna
 
 

Ten Reasons You Should Use Bluetooth

If you are one of the many people who wonder exactly what Bluetooth technology is, you're about to g ... - Christopher Smith
 

8 Tips To Take The Pain Out Of Publishing Your Ezine

Publishing a quality ezine regularly can seem a stressful task, but it doesn't have to be if you fol ... - Silvia Hartmann
 
 

Main » Internet & Computers » Website Development
 

Introduction to MySQL with PHP

 

Author: Haysam Eltabl

Before you actually start building your database scripts, you must have a database to place information into and read it from. In this section I will show you how to create a database in MySQL and prepare it for the data. I will also begin to show you how to create the contacts management database.

Database Construction

MySQL databases have a standard setup. They are made up of a database, in which is contained tables. Each of these tables is quite separate and can have different fields etc. even though it is part of one database. Each table contains records which are made up of fields.

Databases And Logins

The process of setting up a MySQL database varies from host to host, you will however end up with a database name, a user name and a password. This information will be required to log in to the database.

If you have PHPMyAdmin (or a similar program) installed you can just go to it to log in with your user name and password. If not you must do all your database administration using PHP scripts.

Creating A Table

Before you can do anything with your database, you must create a table. A table is a section of the database for storing related information. In a table you will set up the different fields which will be used in that table. Because of this construction, nearly all of a site's database needs can be satisfied using just one database.

Creating a table in PHPMyAdmin is simple, just type the name, select the number of fields and click the button. You will then be taken to a setup screen where you must create the fields for the database. If you are using a PHP script to create your database, the whole creation and setup will be done in one command.

Fields

There are a wide variety of fields and attributes available in MySQL and I will cover a few of these here:

Field Type Description
======== ==========
TINYINT Small Integer Number
SMALLINT Small Integer Number
MEDIUMINT Integer Number
INT Integer Number

VARCHAR Text (maximum 256 characters)
TEXT Text

These are just a few of the fields which are available. A search on the internet will provide lists of all the field types allowed.

Creating A Table With PHP

To create a table in PHP is slightly more difficult than with MySQL. It takes the following format: -------------------------------------------------------------------------------------------------------------- CREATE TABLE tablename {

Fields

} -------------------------------------------------------------------------------------------------------------- The fields are defined as follows:

fieldname type(length) extra info,

The final field entered should not have a comma after it.

I will give full an example of using these later in the section.

The Contacts Database

The contacts database will contain all the conact information for the people you enter and the information will be able to be edited and viewed on the internet. The following fields will be used in the database:

Name Type Length Description
id INT 6 A unique identifier for each record
first VARCHAR 15 The person's first name
last VARCHAR 15 The person's last name
phone VARCHAR 20 The person's phone number
mobile VARCHAR 20 The person's mobile number
fax VARCHAR 20 The person's fax number
email VARCHAR 30 The person's e-mail address
web VARCHAR 30 The person's web address

You may be wondering why I have used VARCHAR fields for the phone/fax numbers even though they are made up of digits. You could use INT fields but I prefer to use VARCHAR as it will allow dashes and spaces in the number, as well as textual numbers (like 1800-COMPANY) and as we will not be initiating phone calls from the web it is not a problem.

There is one other thing you should be aware of in this database. The id field will also be set as PRIMARY, INDEX, UNIQUE and will be set to auto_increment (found under Extra in PH PMyAdmin). The reason for this is that this will be the field identifier (primary and index) and so must be unique. The auto increment setting means that whenever you add a record, as long as you don't specify an id, it will be given the next number.

If you are using PHPMyAdmin or a management program you can now create this in a table called contacts.

Creating The Table In PHP

The following code should be used to create this table in PHP. Some of the code has not been covered yet but I will explain it fully in the next part. -------------------------------------------------------------------------------------------------------------


$user="username";

$password="password";
$database="database";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";

mysql_query($query);
mysql_close();

------------------------------------------------------------------------------------------------------------- Enter your database, MySQL username and MySQL password in the appropriate positions on the first three lines above.

Author Bio:
Haysam Eltabl is an authority in this industry. Haysam has written several articles in the past on this subject.
You can also reach this article by using: web site development, web design & development, website development tampa
 
 
 

Related Articles

 
Wireless Network Security: How to Use Kismet
 
Simple Rules for Affiliate Programs
 
Mobile Auto Detailers; Developing a Web Presence
 
10 Inside Secrets to Google Adwords - Part 2
 
A Cheap Alternative To Broadband?
 
Preparing For A Successful Podcast
 
Web Site Hosting : From Domain Registration to Getting It Online - Part 1
 
Pushing Bad Data- Google's Latest Black Eye
 
How to download games, dvd, divx, movies
 
Where To Get Cheap Web Hosting
 
 
 
 

Self Enhancement

 

Medicine & Treatment

 

Science & Research

 

Teens & Children

 

Fitness & Health

 

Tour & Travel

 

Companies & Business

 

Outdoor & Sports

 

Jobs & Employment

 

Automobile & Automotive

 

Property & Estate

 

Music & Entertainment

 

People & Communities

 

Culture & Art

 

Lifestyle & Fashion

 

Internet & Computers

 

Policies & Law

 

Events & News

 

Home & Garden

 

Games & Play

 

Education & Reference

 

Shopping Online

 

Food & Recipe

 

Finance & Investment

 
Main Privacy of Info Terms of Use  
© 2006 www.crazyweblist.com - All Rights Reserved