Вы находитесь на странице: 1из 12

In this document you will learn MySQL Structured Query Language (SQL) Communicating with a MySQL backend via

via the PHP MySQL , Select, where, order by Database Design Concepts

MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. It is named after developer Michael Widenius daughter, My. The SQL phrase stands for Structured Query Language. MySQL is the most popular Open Source Relational SQL database management system. MySQL is one of the best RDBMS being used for developing web based software applications.

MySQL Data Types


See the table that follows for the potential data or field types in MySQL.

MySQL Quick Reference


Database Manipulation Commands
Use the following commands to create and make changes to your database and tables.

SQL

- STRUCTURED QUERY LANGUAGE

SQL is a standard language for accessing and manipulating databases What Can SQL do? SQL can retrieve data from a database SQL can insert records in a database SQL can update records in a database SQL can delete records from a database SQL can create new databases SQL can create new tables in a database SQL can create stored procedures in a database SQL can create views in a database SQL can set permissions on tables, procedures, and views SQL - often referred to as Structured Query Language) is a programming language designed for managing data in relational database management systems (RDBMS). Originally based upon relational algebra and tuple relational calculus, its scope includes data insert, query, update and delete, schema creation and modification, and data access control. SQL was one of the first commercial languages for Edgar F. Codd's relational model, as described in his influential 1970 paper, "A Relational Model of Data for Large Shared Data Banks".Despite not adhering to the relational model as described by Codd, it became the most widely used database language.

SQL Statements Most of the actions you need to perform on a database are done with SQL statements. SQL can be divided into two parts: The Data Manipulation Language (DML)

Data Definition Language (DDL)

The query and update commands form the DML part of SQL:
SELECT - extracts data from a database UPDATE - updates data in a database DELETE - deletes data from a database INSERT INTO - inserts new data into a database

The DDL part of SQL permits database tables to be created or deleted. The most important DDL statements in SQL are: CREATE DATABASE ALTER DATABASE CREATE TABLE ALTER TABLE DROP TABLE CREATE INDEX DROP INDEX - creates a new database - modifies a database - creates a new table - modifies a table - deletes a table - creates an index (search key) - deletes an index

If you were thinking of what was the difference between MySQL and SQL. Now here is the answer.

SQL is a language used with application that uses in SQL.

databases;

MySQL

is

database

SQL is a common database computer language designed for the retrieval and management of data in relational database management systems (RDBMS) -basically a standard interactive and programming language for querying and modifying data and managing databases. Very standard for uses ranging from the simplest Microsoft Access applications, up to complex multiserver distributed Oracle applications. MySQL is a multithreaded, multi-user SQL database management system (DBMS) providing multi-user access to a number of databases. MySQL is commonly

the back engine database for a great many applications, and often the database of choice for web-based applications.

SQL Statements
Most of the actions you need to perform on a database are done with SQL statements. Entering in Command Prompt Syntax:
cd\ cd xampp\mysql\bin mysql u root after typing the syntax there will be a Welcome to MySQL monitor..notification as seen at left.

SQL syntax
Creating a database Syntax create database database_name; Using the database Syntax use database_name; use csc130; My sample create database csc130;

Now you can use your created database.


Creating table Syntax create table table_name (field1, field2 and so on, primary key(field)); create table student (idno char(10), fullname char(50),course char(30), primary key (idno));

Inserting information into the table


insert into table_name (field1, field2 , .)values(value1,value2,); insert into student (idno, fullname, course ,.)values(001,Kim T. Calipes,BSIT);

Selecting the table


select * from student; select * from table_name;

The output is displaying the information of the student

Order by Syntax
select * from table_name order by name ; select * from student order by name ;

The output is displaying the student information starting the name from A-Z.

Adding Field
Alter table table_name add field_name value ; Alter table student add email value char(30);

The student information add other attribute the email. Now the attribute are idno, fullname, course, email.

Communication with a Mysql backend via the PHP

Connecting to the Database

Before you can connect to the database, you need four things: Database name Host Server name Username Password Connect to the database using the following command (in PHP): $connection = mysql_connect(servername, username, password);

You then need to select the appropriate database by using the following command (in PHP): <?php $database = mysql_select_db(databasename, $connection) or die(couldnt find the database); ?>

Accessing the Database


MySQL commands are inserted within your PHP code to access the database in this way: <?php $query = mysql_query(UPDATE field1 FROM tablename WHERE condition1) or die(Couldnt find the table); $result = mysql_fetch_array($query); ?> //your information has now been updated Inserting/Adding Information to your table
<?php include("Nethost.php"); $s_id=$_POST['s_id']; $s_fname=$_POST['s_fname']; $course=$_POST['course]; $email=$_POST['email']; $query=mysql_query("insert into student values ('$s_id','$s_fname','$course', '$email');"); $message= "Transaction Successfully Inserted to Database..."; ?>

Note: I refer this to what Ive created above, the student is the table_name and s_id is only a variable I address to student idno, s_fname is the student fullname and so on.

Database Design Concepts


Click the link below..