Showing posts with label phpMyadmin. Show all posts
Showing posts with label phpMyadmin. Show all posts

Thursday 9 April 2015

How to use PHP to access a Database

Databases are backbone of today's websites. PHP has support for over 20 databases. MySQL, PostgreSQL and Oracle are widely used databases. Databases are used for storing users registration data, credit card numbers, purchase history, product reviews and many other things.
PHP and phpmyadmin both are used to access databases. Relational database management system is a server which is used to manage data. Data is structured into tables where each table have some no. of columns, each of which has a name and a type. PHP communicates with relational databases such as MySQL and Oracle using structured query language (SQL). The syntax for SQL is divided into two parts. The first, Data Manipulation Language, or DML, is used to retrieve and modify data in an existing database. DML is remarkably compact, consisting of only four verbs: select, insert, update, and delete. The set of SQL commands, used to create and modify the database structures that hold the data, is known as Data Definition Language, or DDL. The syntax for DDL is not as standardized as that for DML, but as PHP just sends any SQL commands you give it to the database, you can use any SQL commands your database supports.

Assuming you have a table called movies, this SQL statement would insert a new row:
INSERT INTO movies VALUES(0, 'fast and furious 7', 2015, 2)
This SQL statement inserts a new row but lists the columns for which there are values:
INSERT INTO movies (title, year, actor) VALUES ('hercules', 2015, 2)
To delete all movies from 2015, we could use this SQL statement:
DELETE FROM movies WHERE year=2015
To change the year for hercules to 2014, use this SQL statement:
UPDATE movies SET year=2014 WHERE title='hercules'
To fetch only the movies made in the 2010s, use:
SELECT * FROM movies WHERE year >= 2010 AND year < 2015 .

 Example :  

This example will show you how to insert form data into database using PHP.

1) First create a html form.

2) Now create a connect.php file.


How to install PhpMyAdmin

Phpmyadmin is used for database management.There are several other software which we need for using it. 
  1. One server (apache, wampserver).
  2. Mysql database.
  3. PHP environment.
  4. Phpmyadmin 4.3 or later.

1) First install Mysql databse on system.

2) After that install apache in system drive in a self made folder.You can named it as you want.

3) After it extract PHP in that folder.

4) After that change php.ini-development.in file into php.ini .

5) After that extract phpmyadmin zip file into apache/htdocs folder.

6) After that copy phpinfo.php file from phpmyadmin folder into apche /htdocs.

7)  After that open the browser and type "localhost/phpinfo.php". You will see the follwing  window :

PHPMYADMIN description