This article mainly solves the following problems: PHP obtains the incremental ID of a MySQL DATA table (PHPgetautoincrementIDvalue); PHP obtains the ID of the last MySQL record; PHP obtains the incremental ID of a MySQL table, obtain the attributes of the mysql data table and obtain AUTO_INCREMENT. $ Table_nameTable1; $ querymysql_query (SH
This article mainly solves the following problems: PHP obtains the incremental ID (PHP get auto increment ID value) of the MySQL DATA table; PHP obtains the ID of the last MySQL record; PHP obtains the incremental ID of the MySQL table. method 1, obtain the attributes of the mysql data table and obtain AUTO_INCREMENT. $ Table_name = Table1; $ query = mysql_query (SH
This article mainly solves the following problems:
- PHP obtains the incremental ID (PHP get auto increment ID value) of the MySQL DATA table );
- PHP obtains the ID of the last MySQL record;
PHP obtains the incremental ID of a MySQL table.
Method 1: Obtain the attributes of the mysql data table and obtain AUTO_INCREMENT.
$ Table_name = "Table1 ";
$ Query = mysql_query ("show table status where name = '$ table_name '");
$ Row = mysql_fetch_array ($ query );
$ Next_inc_value = $ row ["AUTO_INCREMENT"];
This SQL statement was mentioned in a previous article about MySQL commonly used practical SQL statements. It can get the attribute value of the entire table.
The incremental ID obtained in this way will continue to increase even if one ID is deleted, and will not be repeated unless manually set. For example, you only need to set AUTO_INCREMENT to 10000 if you want to start the order number from 10000.
Method 2: Get the Maximum System ID and Add 1 to get the incremental ID.
$ Result = mysql_query ("select max (id) as max FROM table ");
$ Got = mysql_fetch_array ($ result );
$ Next_id = $ got ['Max'] + 1;
It does not completely get the next auto-increment value. Only increase the largest ID by 1, but it is the largest ID value and will not be repeated.
PHP obtains the ID of the last MySQL record.
Method 1: Use the PHP function mysql_insert_id () to obtain the ID of the last inserted record in MYSQL. If the column type of AUTO_INCREMENT is BIGINT, the value returned by mysql_insert_id () is incorrect.
(...)
Read the rest of PHP to get the MySQL incremental ID (9 words)
©Lixiphp for LixiPHP, 2013. | Permalink | No comment | Add to del. icio. us
Post tags: AUTO_INCREMENT, MySQL, PHP, incremental ID
Feed enhanced by Better Feed from Ozh