MySQL and PHP connection database

Source: Internet
Author: User


1. Single-table data backup
Back up the data in the table, only the data has no structure.
Grammar:
SELECT * or field list from table name into outfile path "column Control" "Row control";


Column Control "
Starts with the fields keyword and is controlled by the following information:
Terminate by ' character ' what does each field end with
Enclosed by ' character ' what each field contains
Escaped by ' character ' special characters with what to display

"Row Control"
Start with the Lines keyword,
Starting by ' character ';

Backup:
The data in the database is backed up to a text file in the form of an SQL statement. This approach contains data and structure.
Grammar:
Mysqldump.exe-u user-P database > destination file
Restores:
Method 1:
Use in the CMD environment
Msyql-u user name-p database < source file;

Rights Management
Create user
Grammar:
Create user ' username ' @ ' host name ' identified by ' password ';
Description
User name must be quoted
Password must be quoted
The host name has the following types
LocalHost indicates that the newly created user can log on only on this computer (server)
IP indicates that the newly created user can only login on the specified IP
% No Limit
The newly created user does not have any restrictions


Assigning Permissions to users
Grammar:
Grant all privileges or permissions on the database name ". Table name" to user
Description
All privileges represents all permissions
Create, DROP, ALTER, truncate
UPDATE, INSERT, delete, show

Remove permissions
Grammar:
Revoke all privileges or permissions on the database name ". Table name" from the user;

To delete a user:
Grammar:
Drop user Username

Login (Connect)
mysql_connect (' Host:port ', ' user ', ' password ');
Description
This function is used for PHP connection to MySQL database
Host indicates hostname localhost, this parameter can use IP
Port is the port number MySQL default port number is 3306, if it is 3306 can be omitted
User indicates username
Password means password
This function, if the connection succeeds, returns a resource (3) of type (MySQL link), or false if the failure returns

For UPDATE statements
If it returns TRUE, only the SQL statement can be indicated correctly. If you want to determine if the data is updated successfully, you need to use the mysql_affected_rows () function to determine.
Mysql_affected_rows ();
Number of rows to return impact

For DELETE statements
If it returns TRUE, only the SQL statement can be indicated correctly. If you want to determine whether the data was deleted successfully, you need to use the mysql_affected_rows () function to determine.

MySQL and PHP connection database

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.