PHP Database | Database creation in XAMPP using PHP & MySQL

PHP Database | Database creation in XAMPP using PHP & MySQL

Introduction to Database:

           The Database is a data structure that stores the data in an organized way. Databases contain multiple tables, in which each includes different fields/ attributes for storing data in a structured way. 

Example: Employee Database contains tables like Employee data, Department data, and Company data with several attributes. The employee data table contains Employee ID, Employee Name, Employee Contact No., Employee role, and Employee department. Department table contains the Department Name, Department ID/Code, Department strength, and Department specialization. The company table contains Company Name, Company strength, Company location, and privacy policies. 

Introduction to XAMPP:



XAMPP is a free and open-source cross-platform web server solution stack package developed by Apache Friends, consisting mainly of the Apache HTTP Server, Maria DB database, and interpreters for scripts written in the PHP and Perl programming languages Since most actual web server deployments use the same components as XAMPP, it makes transitioning from a local test server to a live server possible




Steps to Download XAMPP:
 1. Search for XAMPP in Google chrome or Internet Browser.
 2. Click on the official site of Apache Friends i.e., www.apachefriends.org
 3. Click on Download in the navigation bar on the official site.
 4. Different XAMPP server catalog will be provided for Windows, Linux, and OS X. Select the appropriate version for download.
 5 Go to Downloads folder in your system to proceed for Installation.
   Latest version for Windows 7.2.30, 7.3.17 and 7.4.5
   Latest version for Linux 7.2.30, 7.3.17 and 7.4.5
   Latest version for OS X 7.2.30, 7.3.17 and 7.4.5

Launching the XAMPP server after Installation: 

1. Go to C: drive in your system and enter into the XAMPP folder.
2. In the XAMPP folder, double click on the XAMPP control (Application) to open the local host controller.
3. In the XAMPP control panel (latest version 3.2.4), select Start in Actions on Apache and MySQL to host the database.
4. Then Open the Google Chrome or Internet Explorer in your system.
5. Type the Localhost site address in the URL bar as www.localhost/index, in the select the Dashboard. 6. In the Dashboard, www.localhost/phpmyadmin/ will be opened to create the Database.



Creating the (PHP) Database in the XAMPP server:
1. Click on the “New” option on the right side of the page to open the database creation page.
2. Enter the name of your Database in the input space given for “Create database” and click on create button along the same line. Ex.: database name: company.
3. “Create table” portal will be opened, there enter the Table name and specify the number of columns.
4. Enter the Table Name and Number of columns, then click on the “Go” button to create the table. Ex.: our employee
5. Enter the column name, data type, length (size of), and in Index specify the Primary or Unique key for all the columns which are to be created.
6. Click on the Save button at the button right corner of the page, to create the database in the XAMPP server.

MySql Datatypes in Table creation:

Basic Datatypes: 
1. INT: Integer datatype to specify the integers or numbers.
2. TEXT: Text data type is to specify the string or alphabetical characters.
3. DATE: Date data type is to specify the date-related data to the database.
4. VARCHAR: This data type is to specify the string with alpha-numeric characters.

Numeric Datatypes:
1. TINYINT
2. SMALLINT
3. MEDIUMINT
4. INT
5. BIGINT
6. DECIMAL
7. FLOAT
8. DOUBLE
9. REAL
10. BIT
11. BOOLEAN
12. SERIAL

Date and Time Datatypes:
1. DATE
2. DATETIME
3. TIMESTAMP
4. TIME
5. YEAR

String Datatypes: 
1. CHAR
2. VARCHAR
3. TINYTEXT
4. TEXT
5. MEDIUMTEXT
6. LONGTEXT
7. BINARY
8. VARBINARY
9. TINYBLOB
10. MEDIUMBLOB
11. BLOB
12. LONGBLOB
13. ENUM 14. SET

Spatial 
1. GEOMETRY
2. POINT
3. LINESTRING
4. POLYGON
5. MULTIPOINT
6. MULTILINESTRING
7. MULTIPOLYGON
8. GEOMETRYCOLLECTION

JSON 
1. JSON


Index in the creation of table attributes:

1. Unique Key: To create unique index you must have CREATE ANY INDEX privilege. Here the concept is bit different. User needs to check the values of the table to create unique index. If table contains uniquely identified values in specified column then you should use unique index. Especially while creating the table if we specify the primary key then unique index is automatically created on that column. But for Unique key constraint columns you separately need to do indexing. Kindly make sure that Unique key indexes created on the columns which has unique values only.

2. Primary Key: A primary key is a field in a table that uniquely identifies each row/record in a database table. Primary keys must contain unique values. A primary key column cannot have NULL values. A table can have only one primary key, which may consist of single or multiple fields.

3. Index Key: It is a data structure technique which is used to quickly locate and access the data in a database. Indexes are created using a few database columns. The first column is the Search key that contains a copy of the primary key or candidate key of the table.

4. Full Text key: A full-text index is a special type of index that provides index access for full-text queries against character or binary column data. A full-text index breaks the column into tokens and these tokens make up the index data.

5. Spatial Key: A spatial database is a database that is optimized for storing and querying data that represents objects defined in a geometric space. Most spatial databases allow the representation of simple geometric objects such as points, lines and polygons.



Contributor

Show your Writing skill on cwipedia ,for contribution email us on business@cwipedia.in or go to contribute.cwipedia.in
The above article is contributed by.

Rahul Aradhya T R

Comments