PHP MySQL Database

Source: Internet
Author: User
Tags php mysql table definition

PHP MySQL Database


Classification of databases:

Hierarchical database: Text structure similar to XML (HTML)

Mesh Database:

Relational database:

Mainstream database:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/76/58/wKioL1ZQMWyQM_nkAABAAFwECeQ095.jpg "title=" Maindbms.jpg "alt=" Wkiol1zqmwyqm_nkaabaafweceq095.jpg "/>

MySQL is a relational database management system

Sql:struct Query Language structured queries language. is actually an "international" standard

A variety of relational databases, in fact, is to achieve (and expand) the standard of a product

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/76/5A/wKiom1ZQMZ-BQ26BAACEn_hkAJA999.jpg "title=" Relationdb.jpg "alt=" Wkiom1zqmz-bq26baacen_hkaja999.jpg "/>


The nature and performance of database storage:

The essence is that a large number of "data values" through the database management system for some complex but logical structure of the clear and orderly storage

Performance: In fact, the file is stored


Common terminology for relational databases:

Statistics: data;

Databases: Database;

Database management system: DBMS; Database management System

Table (data Sheet): table;

Fields: Field

Columns: Column

Row: Row

Records: Record



Basic structure of the database system:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/76/5A/wKiom1ZQNYWg_fZuAACj3urbHRU023.jpg "title=" Mysql_ Struct.jpg "alt=" Wkiom1zqnywg_fzuaacj3urbhru023.jpg "/>

MySQL system-level operations and basic syntax rules:

Command line mode: NET Start/stop mysql

Service mode: Control Panel > Administrative Tools > Services > MySQL > Start/stop

Login/Exit Basic operation:

Mysql-hlocalhost-uroot-p;

Mysql-h127.0.0.1-utest-p;

Backup/RESTORE Database:

Backup: mysqldump-h server address-u user name-P database name > file name to store

Recovery: mysql-h server address-u user name-p database name < database name to recover

Basic code and procedures for manipulating databases in PHP:

1: Connect to database: $mylink = mysql_connect ("localhost", ' root ', ' root ');

2: Set the connection code (usually UTF8): mysql_set_charset (' UTF8 '); can also be used: mysql_query ("Set names UTF8");

3: Select the database (if necessary): mysql_select_db ("database name"); Also available: mysql_query ("Use database name");

4: Execute SQL command

$result = mysql_query ("Almost any SQL statement");

The returned results usually need to be handled in two different situations:

If it is a statement with no return data:

If $result is true, indicates successful execution

If $result is false, it indicates that the execution failed

If there is a statement that returns data:

If $result is false, it indicates that the execution failed

Otherwise, the execution succeeds and you need to continue extracting the data from the results and showing it

Supplemental SQL statements:

Set names GBK;

Use DatabaseName;

DESC Table Name: Displays the "Structure information" of a table and returns a result set (similar to a SELECT statement)

Functions to supplement PHP operations:

$record = mysql_fetch_array (result set $result);

Mysql_num_rows ($result); Get the number of rows in the result set

Mysql_num_fields ($result); Get the number of columns in the result set

Mysql_field_name ($result, $i); Gets the name of the I field in the result set (I starts with 0)


mSQL Data Definition Language DDL (language):

Database definition statement:

1: Create the database: creates the [if not exists] databasename [charset character set][collate character collation];

Description

1:if NOT exists is used to determine if the database name exists, and the statement is not executed if it exists

2: Character set: The character encoding name used when the intent data is stored in this database is usually utf8, or it can be GBK

3: Character collations are not usually set, but instead use the default rules for the strings you set (each character set has a default collation);

What is collation: Set the rules for how all the characters in a character set are sequenced

Show all character sets: Show CharSet;

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/76/59/wKioL1ZQWEKi2vyhAAC_ZY2d018812.jpg "title=" 01.jpg "alt=" Wkiol1zqweki2vyhaac_zy2d018812.jpg "/>

Show all collations in MySQL: Show collation;

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/76/5A/wKiom1ZQWbezPiBdAACZpT5Lvqk096.jpg "title=" 01.jpg "alt=" Wkiom1zqwbezpibdaaczpt5lvqk096.jpg "/>

2: Modify the database, so-called modify the database is to modify the data option value

ALTER DATABASE name character set= new character set collate= new proofing set;

3: Delete Database

drop database name;

Other Database related statements:

Select (Enter) a database: use database name;

Show all databases: show databases;

Displays the creation statement for a database: show create database name;

field type, i.e. data type

Table definition Statements

View definition Statements

Database (table) Design Introduction:

mSQL Data Manipulation language DML (manipulation language)

Insert data:

Delete data:

To modify the data:


PHP MySQL Database

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.