How to insert an auto-increment id

Source: Internet
Author: User
How to insert an auto-increment id data table that is already set to auto-increment.
// Insert_arr (table name, field name, insert value) --- "get the array inserted into the database // public function insert_arr ($ tab_name, $ tab_filed =" ", $ insert_arr ){}
}
Whether to insert full fields or select fields.
If (omitted ){
When a table has more than 10 fields, it seems that this process is omitted, but how to give the value to the auto-increment ID field.
When the table structure is modified later, the code certainly reports an error when the field is sorted or added.
} Else {
I have to write more than 10 fields in a table. in the future, the table should not be modified. Is it too lazy ....
}


Reply to discussion (solution)

The auto-increment field can be default, or you can assign 0 or null according to your database configuration.

You seem to be writing database operations
However, the $ tab_filed parameter is not required to be passed.
Because $ insert_arr should be an association array, and the association key should be the field name.

Upstairs positive solution, field name is not necessary

If the library is set to auto-increment, there is no need to insert it.

I know that the key is that you do not write the field name. isn't it all fields by default? you have to give it a value.
In mysql, null values can be inserted, but cannot be inserted through php.

I know that the key is that you do not write the field name. isn't it all fields by default? you have to give it a value.
In mysql, null values can be inserted, but cannot be inserted through php.

Just give NULL.

Thank you.


I know that the key is that you do not write the field name. isn't it all fields by default? you have to give it a value.
In mysql, null values can be inserted, but cannot be inserted through php.

Just give NULL.
$ SQL = "insert into test values ('u5', 'u5', NULL.
But I am talking about this situation. what value should $ a provide? $ A is an auto-incremental ID.
$;
$ SQL = "insert into test values ('u5', 'u5', $ )";
.



I know that the key is that you do not write the field name. isn't it all fields by default? you have to give it a value.
In mysql, null values can be inserted, but cannot be inserted through php.

Just give NULL.
$ SQL = "insert into test values ('u5', 'u5', NULL.
But I am talking about this situation. what value should $ a provide? $ A is an auto-incremental ID.
$;
$ SQL = "insert into test values ('u5', 'u5', $ )";
.

Why do I have to write a variable? is there any other purpose?

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.