Review
Query: Grouping (GROUP by: Statistics), having (condition), sort (order by), limiting (limit offset,length)
Union query: Record overlay, sort (order by:1. Must match limit, the query clause must use parentheses)
Subquery: Sub-query classification (scalar, column, row (build row Element) and table (data Source: from))
View: Virtual table (with structure, no data), view data operation PHP operation MySQL
1. What is MySQL software architecture?
c/S software structure
The server must be accessible through the client.
2. What does PHP mean by working with MySQL?
PHP simulates the client to operate the database.
PHP can not operate mysql,mysql for PHP to provide an operational extension, PHP needs to load the extension to implement the operational database. PHP Operational Database Procedures
1. Load MySQL operation extension for PHP
A) allow PHP to load the extension
b) Specify the extension path
PHP has become a client that can operate the MySQL server.
2. Connection authentication: Locate the computer where the MySQL server is located and the port you are listening on, then enter the correct user name and password: mysql.exe–h host –p port –u username –p Password
PHP operation MySQL, via function mysql_connect connection operation
Resource mysql_connect (host address: port, user name, password); Connecting Resources
Multiple connections, return to the same connection resource
PHP can be specified by the fourth parameter of mysql_connect, whether to obtain a different connection resource, the default is the same resource.
3. PHP as client: Preparing SQL statements
4. PHP as client: Send SQL statement/receive returned execution result
Mixed mysql_query (The SQL statement to be sent [, the specified connection resource]);
Boolean type result: The SQL statement to execute has no return value
return value type result: To execute a SQL statement with a return result, the returned result is a resource: Result set resource
5. PHP as client: Parse return result (Resource)
Mixed mysql_fetch_row (Result set Resource): Extracts a row of records from the result set, stores the data of all fields of the record as elements into an array, and the subscript of the array is automatically generated (indexed): The principle of the application is the result set pointer, if there is data returned to the array, No data returned false.
6. Releasing resources: disconnecting, releasing the connection resources
Mysql_free_result (Result set Resource): Release result set resource
Mysql_close (Connection Resource): Disconnecting resources
Flow chart
Full PHP operation MySQL
1. To process errors that may occur
Mysql_errno (): Error number for MySQL error
Mysql_error (): Error description for MySQL error
2. Complete processing of data results
1. Connection authentication
2. Setting the character set
3. Select a database
4. Data manipulation: Adding and deleting changes
4.1 New data
In case of new data, you will usually get the self-growth ID of the new data.
MYSQL_INSERT_ID (): Gets the self-growth ID of the last new operation, if no self-growth is 0
4.2 Query Operations
The result set can be manipulated by three functions, resulting in a different result, both returning an array
Mysql_fetch_array (Result set resource [, get mode]): Takes a record from the result set, returns an associative index array that is the default, or you can specify the fetch mode by getting the schema, either indexed or associative.
Mysql_fetch_row (): Gets an indexed array, internally through Mysql_fetch_array (, Mysql_num)
MYSQL_FETCH_ASSOC (): Gets an associative array where the key name is the field name in the table and the value is the data for the field
The above three functions are implemented through the result set pointer movement, which moves the pointer when the data is finished (move the pointer down)
5. Releasing Resources
Releasing result set resources and connection resources
20150105--php+mysql Sign Up-01