MySQL's several out-of-table connections and PHP operation MySQL functions

Source: Internet
Author: User
Tags mysql functions

Internal Connection

According to the conditions, the left table's daily records match the right table, if the conditions are met, the field content will be saved, if not, it will not be saved;

Grammar:

Select *| Field List from Left Table INNER JOIN Right Table on Left Table . Field = Right Table . Field ...;

Inner can be omitted;

Simple version syntax

Select *| Field List from Left Table Join Right Table on Left Table . Field = Right Table . Field ....;

External Connection Left outer connection

Grammar:

Select *| Field List from Left Table Left join Right Table on Left Table . Field = Right Table . Field ...;

The same as the inner connection, only one by one points difference: Outside the connection, no match succeeded, the left table field contents will be saved, and the right table is saved as null .

Right Outer connection

Grammar:

Select *| Field List from Left Table Right join Right Table on left . Field = Right Table . Field ...;

The same as the inner connection, only one by one points difference: Outside the connection, no match succeeds, the field contents of the right table are saved, and the left table is saved with null .

Natural Connection

Rules:

As long as two of the table has the same field name, the system is considered a connection condition, will be active to match the two same field name value is the same, if the same field name of two tables the same value, the match is considered successful; if more than one field name is the same in both tables, Then all the same field names have the same values to match the success!

Natural Inner Connection

Grammar:

left Table Natural INNER join right table

As with the internal connection, the field that does not match successfully is deleted directly;

Natural External Connections

Grammar:

left Table natural left|right join right Table

Same as the outer join, only the matching condition is the system.

PHP Operation MySQL

Mysql_connect function: Connecting to a database

Grammar:

Mysql_connect (' native name ', ' username ', ' password ');

disconnecting requires using the Mysql_close function!

mysql_query function: send operation instruction

mysql_query (" operation Instructions ")

The mysql_query function returns a Boolean value if the operation fails (frue), which, if successful, may return a Boolean value (True ) may also return a resource result set

So how do you extract the resource result set?

Mysql_ Fetch_array () functions: Extracting resource result sets

The resource result set returns an array of associations and indexes, one fetch, an array pointer down, and the next row of values

Mysql_both: returns both the associative and indexed arrays as well as the default values!

Mysql_fetch_assoc: returns only associative arrays!

Mysql_fetch_row: returns only indexed arrays

After the resource result set is used, you should release it voluntarily:

use another system function mysql_free_result ( result set resource );

Error Debugging function

because PHP Connection MySQL will not error, so you need to use the wrong debug function to error

Mysql_errno: Error encoding

Mysql_error: error message

MySQL Data backup Text Backup:

Copy and paste the data table, but each time the table is copied, wasting space

Data backup:

Grammar:

Select *| Field List Into outfile file Address from Table name ;

Attention:

The directory name in the file address cannot be omitted and cannot be backed up to a file that has already stored the data, and the file must be MySQL system built itself, that is, you only need to specify a directory, and then set the file name, theMySQL system will help you build a new!

Sql Backup

Grammar:

Mysqldump-hlocalhost P3306-uroot p Database name [ datasheet 1 Data Sheet 2 ... ] > storage path

Restore Syntax

Grammar:

Method 1

Mysql-hpup database name < Backup path

Method 2

SOURCE backup Path ;

MySQL's several out-of-table connections and PHP operation MySQL functions

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.