Database
What is DataBase?

In database we store our data. Like MSExcel etc. But MSExcel is not DataBase software. DataBase Software are Mysql, Oracle,Sybase etc. Main benefit of database software is that user can reterive data as per requirement. There is no need to see whole data. By DataBase data duplication will be remove. And many more has feature on DataBase as compare to File processing System(like MS Excel).
In DataBase data store in tables. And table has combination of rows and columns. Generally database has two architecture.

Embedded DataBase:-

Embedded DataBase store on one machine.  This database can’t use over networks means database can not be shared by different machine.

Client/Server DataBase:-

Client/Server DataBase basically for networks.  Means multiple user do work on same data simultaneously.

Some DataBase software are:-
MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, and Generic ODBC
PHP support all these  database but generally we use MYSQL .

MySQL

MySQL is a database software and basically used on the web. PHP and Mysql has good combination for developing website. MySQL is open source like PHP.

How to create DataBase in MySQL

1-Open Browser
2-Type this URL http://localhost/phpmyadmin/ on Address bar. Press Enter
3-For New DataBase. Write DataBase Name. Then Click on Create Button.
4-For Create table Enter table name and number of fields. Click on Go
5-Type field name and Select Datatype
6-Click on Save Button.
For Insert Data in DataBase click on INSERT  TAB and Enter Data.

Some use full Datatype in mysql

DataType

Data

Description

Range/Format

INT

Numeric

Normal-Sized  Integer

-2147483648 to 2147483647(4 Bytes)

MEDIUMINT

Numeric

Medium-sized  Integer

-8388608 to 8388607 (3 Bytes)

SMALLINT

Numeric

Small Integer

-32768 to 32767 (2 Bytes)

TINYINT

Numeric

Very small Integer

-128 to 127 (1 Bytes)   

FLOAT

Numeric

Single precision floating-point Number

1.176*10-38  to 3.403*10+38

DOUBLE

Numeric

Double precision floating-point Number

2.225*10-308 to 1.798*10+308

DECIMAL

Numeric

Float stored as string

Maximum range same as double

DATE

Date/Time

Date

YYYY-MM-DD

DATETIME

Date/Time

Date and Time

YYYY-MM-DD hh:mm:ss

TIME

Date/Time

Time

Hh:mm:ss

CHAR

Character Type

Fixed-length String

0-255 characters

VARCHAR

Character Type

Varible-length String

0-255 characters

TEXT

Character Type

Normal-size Text

0-65535

How to connect PHP with Mysql

mysql_connect()
This function connect you with Mysql DataBase.
Example
$conn=mysql_connect(‘localhost’,’root’,’pass’);
Here first parameter is hostname, second parameter is username, third parameter is password. All these three parameter is necessary to connect with mysql database.
mysql_close()
This function disconnect you with Mysql DataBase.
Example:-
mysql_close($conn);
If parameter is not specifiy then last mysql connect will close.

Example 1:- You test the following code to check you are connect with database or not.

<?php
$con=mysql_connect('localhost','root','');
if($con)
echo "Mysql Connected";
else
echo "Mysql not Connected";
?>

Output:
Mysql Connected
Note: if  condition is true so Output show Mysql Connected.

How to connect with database.

mysql_select_db("databasename","$conn”);

This function is used to select database. If database exist this function return true otherwise return false.

Example 2:-

<?php
$con=mysql_connect('localhost','root','');
if($con)
echo "Mysql Connected";
else
echo "Mysql not Connected";
$database=mysql_select_db('test',$con);
if($database)
echo "<br>"."DataBase Connected";
else
echo "DataBase not Connected";
?>

Output:
Mysql Connected
DataBase Connected
Note: if both Condtion is true so above output show.

Example 3:-

<?php
$con=mysql_connect('localhost','root','');
if(!$con)
die('Mysql Not Connected');
$database=mysql_select_db('teset',$con);
if(!$database)
die('DataBase Not Connected');
?>

Note: Use this code for developing website.

Manage DataBase through through MySQL

After connecting DataBase. we start to manage database. For mange database through DataBase. There are mainly four query.

Insert query:- To insert data into DataBase
Delete query:- To Delete data from DataBase
Update query:- To Update data into DataBase
Select query:- To Reterive data from DataBase.


Previous
Next