MySQL extension for php: MySQL database overview

Source: Internet
Author: User
Tags php mysql php mysql extension

Source: http://www.ido321.com/1023.html

First, SQL: Structured Query Language

SQL (Structured Query Language) is an advanced, non-procedural language that is designed to query and modify database information and to manage and maintain databases. The SQL language structure is simple and powerful, and it is supported by many DBMS.

SQL is divided into four parts:

Data Definition language (DDL): used to define and manage data objects, including databases, data tables, and so on. such as Create/drop/alter, etc.

Data Manipulation Language (DML): manipulate data contained in database objects, such as Insert/update/delete, etc.

data Query Language (DQL): queries the data contained in database objects and returns data results, such as Select

Data Control Language (DCL): manages database objects, including rights management and data changes, such as Grant/revoke/commit/rollback

Ii. Common MySQL Operations

1. Connection and shutdown:mysql–h "Server host Address"-u username –p user Password quit and exit to close the connection

2. Create user and authorization: GRANT permissions on the database. Data table to User name @ login host identified by "password"

   1://Add new user, named Phper  password Dwqs, login on any host, have query, insert, modify, delete permissions for all databases
   2://Before creating a user, log in as root user first
   3:  GRANT select,insert,update,delete on * * to Phper@ "%""Dwqs" 
   4:
   5://create user and authorize only for MyDB database
   6:"Dwqs"

3. Database Operation

   1://Create a database named Test
   2:  CREATE DATABASE [if not exists] test;
   3://delete test
   4:  drop Database [if exists] test
   5://Display database list
   6:  show Databases
   7://using the test database
   8:use test

4. Data table Operation

   1://create a table in test, the table name is Dwqs
   2:
   3:  <
   4:intnull auto_increment,
   5:nulldefault' ',
   6:nulldefault' www.ido321.com,
   7:  Email varchar (+) NOT null default '
   8:  >
   1://View the table in the test database
   2:  Show Tables
   3://View the structure of the DWQS table
   4:  desc DWQS  or  description Dwqs
   5://delete Dwqs table
   6:  drop table Dwqs

5. Data Sheet Content Management

   1://Insert record
   2:  Insert [into] table name [(field name 1), (field Name 2),..., (field name N)] VALUES (' value 1 ',' value 2 ',..., ' value n ')
   3://update record
   4:  Update table name set field Name 1 = Expression 1[, field name 2 = expression 2,..., field name n= expression N]
   5:  [WHERE Condition] [order BY field] [number of limit lines]
   6://delete record
   7:  Delete from table name [WHERE Condition] [order BY field] [number of limit rows]
   8://query record
   9:  SELECT [All|distinct]
  Ten:  {*|table.*|[ Table.] Field1[as alias1],[table.] Field2[as alias2][,...]}
One   : from tablaname[,...] [In Externaldatabase]
  :  [Where Condition][group by field][having condition][order by field][limit rows]

Description:  in the query, distinct is used to exclude duplicate data, returning only one, and the default is all. As is used to label the column alias: field name as ' Alias ', in the results of the query, the field name is displayed as an alias. In for subqueries, you can also use like to make fuzzy queries, such as "%php%", which contains the word "PHP", which represents 0 or any character; -shaped such as Dwqs,dwrs, _ denotes an arbitrary character. Group BY is a grouping of query results. SQL expressions or functions, such as count (), can also be embedded in select .

6, modify the table

   1://This "modification" mainly modifies the structure of the table, such as adding fields, modifying field properties, etc.
   2:  ALTER TABLE name action
   3:specific content of//action
   4://Add new field
   5:  ALTER TABLE name add field name Description [first|after column name]
   6:intnull  //Add a QQ field for DWQS table, type is integer, not empty
   7://Modify field
   8:  ALTER TABLE name change (Modify) List description
   9:Default//Change the type of the QQ field to varchar, which is 0
  :default//Change the type of QQ field to varchar, and defaults to 0
One   ://Modify table name
  :as new table name

Description : [first|after column name] Table name the position of the new field, first inserts the field into the column, and the After column names the field after the specified column name. This value is not specified and is added by default at the end.

The difference between modify and change: In addition to changing the type, change the column name, all QQ fields appear two times, the previous one is the old column name, the next one is the new column name. and modify does not modify the column name function, all QQ only appeared once

Next: php mysql extension: php access to MySQL common extension functions

MySQL extension for php: MySQL database overview

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.