PHP 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.
Example 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

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

Note 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

Basic PHP Syntax
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.

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

Output: Mysql Connected

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

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

Example

<?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: 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

Insert Query
Mysql Insert Query,To insert data, into MySQL table use mysql insert query.
Syntax 1:

 insert into table_name(field1,field2,...fieldN) values(value1,value2,..valueN);

Syntax 2:

insert into table_name set field1=value1, field2=value2, ….N;

Example 1:-

insert into tbl_feedback(name,email) values('Johan', 'test@gmail.com')

Example 2:-

 insert into tbl_feedback set name='Johan', email='test@gmail.com'

Example 3:-

insert into tbl_feedback values('Johan', 'test@gmail.com')

Note :- if you insert all field then it is not necessary to declare all fields just like you can see above Example 3

xhamster
How to Buy Luxury Watches for Under
pornhub but the rivalries among the judges were fiercer

All You Need To Know About Laptop Bags
xhamster 6 folks exciting and totally dull abilities

6 SEXY DOUBLE H BOOTS FOR WOMEN
porno A short hike on Camelback Mountain

How Much Cotton Does it Take to Make a Shirt
porno Dresses were often worn to school during the ’50s

Kate Gosselin Models at New York Fashion Week
porno and trendy jewelry

Polo Boots choosing for you
youjizz Her make up was stunning when coupled with the gown shading

Banner of the Stars II Vol
jogos de vestir which takes about twenty minutes

09 Fashion Trend of Jewelry and Accessories
cartoon porn These important elements lacked attention
This entry was posted in   PHP.
Bookmark the   permalink.

Admin has written 171 articles