PHP video tutorial of Zhongyuan University

Source: Internet
Author: User
Http://www.linji.cn/1136.htm

1. TIME_TO _SEC(Time)

Returns the time parameter, which is converted to seconds.

Mysql> select TIME_TO_SEC ('22: 23: 00 ');
-> 80580
Mysql> select TIME_TO_SEC ('00: 39: 38 ');
-> 2378

2. getenv ('')

Obtain the value of an environment variable (environment variable)

$ Ip = getenv ('remote _ ADDR ');

3. strlen Function

Get String Length
Syntax: int strlen (string str );
Return Value: integer
Function Type: Data Processing

Description

This function returns the specified String Length.

4. substr

Obtain part of the string

Syntax: string substr (string, int start, int [length]);
Return Value: String
Function Type: Data Processing

Description

This function extracts the length from the start character of the string. If start is a negative number, it is counted from the end of the string. If the parameter length can be omitted, but it is a negative number, it indicates that the maximum length is obtained.

Example

<?
Echo substr ("abcdef", 1, 3); // return "bcd"
Echo substr ("abcdef",-2); // return "ef"
Echo substr ("abcdef",-3, 1); // return "d"
Echo substr ("abcdef", 1,-1); // return "bcde"
?>
5. query the information (select the information you want)

$ SQL = "SQL syntax here ";
$ Conn = mysql_connect ($ host, $ user, $ pass );

// Word query: mysql_connect

/*
Mysql_connect -- open a connection to the MySQL server

If the connection succeeds, a MySQL connection ID is returned. If the connection fails, FALSE is returned.

Mysql_connect () establishes a connection to the MySQL server. If no optional parameter is provided, use the following default values: server = 'localhost: 100', username = username of the server process owner, and password = NULL.

Server parameters can include port numbers. For example, "hostname: port" or the path to the local socket, for example, ":/path/to/socket" on the local machine ".

Note: Whether "localhost" or "localhost: port" is specified as the server, the MySQL client library overwrites it and tries to connect to the local socket (name pipeline in Windows ). If you want to use a TCP/IP connection, replace "localhost" with "127.0.0.1 ". If the MySQL client library tries to connect to the wrong local socket, set mysql. default_host to the correct path in the PHP configuration and leave the server field blank.

": Port" is supported by PHP 3.0B4.

":/Path/to/socket" is added from PHP 3.0.10.

You can add @ before the function name to suppress the error message generated when the function fails.

If the same parameter is used to call mysql_connect () for the second time, a new connection is not established, but an opened connection ID is returned. The new_link parameter changes this behavior and makes mysql_connect () always open a new connection, even when mysql_connect () was previously called with the same parameter. The client_flags parameter can be a combination of the following constants: MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE, or MYSQL_CLIENT_INTERACTIVE.

Note: The new_link parameter is available in PHP 4.2.0.

The client_flags parameter is available in PHP 4.3.0.

Once the script ends, the connection to the server will be closed. Unless mysql_close () has been called before to close it.
*/

// Configure //-----------------------------------------------------------------------------------------

Mysql_select_db ($ database, $ conn );

/*
If the call succeeds, TRUE is returned. If the call fails, FALSE is returned.

Mysql_select_db () sets the active database on the server associated with the specified connection identifier. If no connection identifier is specified, the last opened connection is used. If no connection is enabled, this function will call mysql_connect () with no parameter to open and use it.

Each subsequent mysql_query () call will act on the active database.
*/

// Configure //-----------------------------------------------------------------------------------------

Mysql_insert_id ()

// Configure //-----------------------------------------------------------------------------------------

Mysql_insert_id -- get the ID generated by the previous INSERT operation

Mysql_insert_id () returns the AUTO_INCREMENT ID generated in the previous INSERT query in the given link_identifier. If link_identifier is not specified, the last opened connection is used.

If no AUTO_INCREMENT value is generated in the previous query, mysql_insert_id () returns 0. If you want to save the value and use it later, make sure that mysql_insert_id () is called immediately after the query that generates the value ().

Note: The SQL function LAST_INSERT_ID () in MySQL always saves the newly generated AUTO_INCREMENT value and is not reset between Query statements.

// Configure //-----------------------------------------------------------------------------------------

$ Result = mysql_query ($ SQL );

// Word query: mysql_query

/*
Mysql_query -- send a MySQL Query

Mysql_query () sends a query to the active database on the server associated with the specified connection identifier. If link_identifier is not specified, the last opened connection is used. If no connection is enabled, this function will try to call the mysql_connect () function without parameters to establish a connection and use it. The query results are cached.

Note: The query string should not end with a semicolon.

Mysql_query () Only returns a resource identifier for SELECT, SHOW, EXPLAIN or DESCRIBE statements. If the query execution is incorrect, FALSE is returned. For other types of SQL statements, if mysql_query () is executed successfully, TRUE is returned. If an error occurs, FALSE is returned. If the return value is not FALSE, the query is legal and can be executed by the server. This does not indicate any affected or returned number of rows. It is very likely that a query is successfully executed but does not affect or no rows are returned.

If you do not have the permission to access the table referenced in the query statement, mysql_query () returns FALSE.

If the query is successful, you can call mysql_num_rows () to check the number of rows returned by the SELECT statement, or call mysql_affected_rows () to check the values corresponding to DELETE, INSERT, the number of rows affected by the REPLACE or UPDATE statement.

A new result identifier is returned only for SELECT, SHOW, DESCRIBE, or EXPLAIN statement mysql_query (). It can be passed to the functions of mysql_fetch_array () and other processing result tables. After processing the final result set, you can call mysql_free_result () to release the associated resources, even though the memory is automatically released after the script is executed.
*/

// Configure //-----------------------------------------------------------------------------------------

Mysql_close ($ conn );

6. add, delete, and modify

$ SQL = "DELETE FROM gbook WHERE id = '$ id'"; //' $ id' must be enclosed in single quotes

New SQL statement:

Insert into 'gbook' ('id', 'name', 'sex', 'email ', 'info', 'IP', 'Time _ at') VALUES (NULL, '$ name',' $ sex ',' $ email ',' $ info', '$ ip', NOW ())"

It can be rewritten:

Insert into gbook VALUES (NULL, '$ name',' $ sex', '$ email', '$ info',' $ ip', NOW ())

The id here is the primary key and is automatically numbered. If you use the abbreviation above, you must replace it with NULL. You cannot enter it as ''(two single quotes) or empty. Otherwise, data cannot be added to the database.

// Configure //-----------------------------------------------------------------------------------------

$ SQL = "SQL syntax here ";
$ Conn = mysql_connect ($ host, $ user, $ pass );

$ Result = mysql_db_query ($ database, $ SQL, $ conn );

/*
Mysql_db_query -- send a MySQL Query

Returns a positive MySQL result resource number based on the query results. If an error occurs, FALSE is returned. This function returns TRUE/FALSE for the INSERT/UPDATE/DELETE query to indicate success or failure.

Mysql_db_query () Select a database and execute the query on it. If no optional connection identifier is provided, this function will find an opened connection to the MySQL server. If no connection is found, mysql_connect () will be called without parameters ().

Note that this function will not switch back to the database previously connected. In other words, you cannot use this function to temporarily Execute SQL queries in another database, but you can only switch back manually. We strongly recommend that you replace this function with the database. table syntax in SQL queries.

Note: This function is not recommended since PHP 4.0.6. Do not use this function. Replace it with mysql_select_db () and mysql_query.
*/

// Configure //-----------------------------------------------------------------------------------------

$ Row = mysql_fetch_row ($ result );

// Word query: mysql_fetch_row

Output from the earliest record

/*
Returns the array generated based on the row obtained. If no more rows exist, FALSE is returned.

Mysql_fetch_row () retrieves a row of data from the result set associated with the specified result ID and returns it as an array. Each result column is stored in an array unit, and the offset starts from 0.

Call mysql_fetch_row () in sequence to return the next row in the result set. If no more rows exist, FALSE is returned.

Note: The field names returned by this function are case sensitive.

1. $ r = mysql_fetch_row ($ result) You can put the current record in the form of an array to the current $ r, so that you can use $ name = $ r [0]; and $ pwd = $ r [1]; To get the value, and after $ r = mysql_fetch_row ($ result) is executed, the pointer automatically points to the next record, in this way, you can use the WHILE loop to retrieve all records in $ result. However, this code has bugs. You only need to remember this structure.
While ($ r = mysql_fetch_row ($ result )){
...
}
2. if $ result has already pointed to the end of the record, that is, there is no current record. If $ r = mysql_fetch_row ($ result) is executed, FALSE is returned, and the while loop condition is no longer met, the loop ends, so this structure is used to traverse all records in $ result.
*/

// Configure //-----------------------------------------------------------------------------------------

Mysql_close ($ conn );

/*
Mysql_close () closes the connection to the MySQL server associated with the specified connection ID. If link_identifier is not specified, the last opened connection is closed.

Generally, mysql_close () is not required, because the opened non-persistent connection is automatically closed after the script is executed. See release resources.

Note: mysql_close () does not close persistent connections established by mysql_pconnect.

Release resources:

Because the PHP4 Zend engine introduces a resource counting system, it can automatically detect that a resource is no longer referenced (the same as Java ). In this case, all external resources used by the resource are released by the garbage collection system. For this reason, some free-result functions are rarely used to manually release the memory.

Note: Persistent database connections are special and will not be damaged by the garbage collection system.
*/

// Configure //-----------------------------------------------------------------------------------------

Mysql_free_result ($ result );

// Word query: mysql_free_result

/*
Mysql_free_result () releases all memory associated with the result ID result.

Mysql_free_result () is called only when considering how much memory will be occupied when a large result set is returned. After the script is completed, all associated memory will be automatically released.

If the call succeeds, TRUE is returned. If the call fails, FALSE is returned.
*/

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.