What is the correct syntax for defining an auto-increment primary key in a MySQL table using PHP?
When defining an auto-increment primary key in a MySQL table using PHP, you need to include the "AUTO_INCREMENT" attribute in the column definition for the primary key field. This attribute will automatically generate a unique value for each new record inserted into the table. Additionally, you should specify the primary key constraint using the "PRIMARY KEY" keyword.
// Define a MySQL table with an auto-increment primary key using PHP
$query = "CREATE TABLE table_name (
id INT AUTO_INCREMENT PRIMARY KEY,
column1 VARCHAR(50),
column2 INT
)";
Keywords
Related Questions
- How can PHP developers protect against SQL injection vulnerabilities in their code?
- What are the alternatives to storing massive amounts of data in PHP arrays for efficient processing?
- How can the input data from a form be sorted and organized before writing it to a file in PHP to meet specific requirements or standards?