INSERT INTO statement
The INSERT INTO statement is used to insert a new row into the table.
Grammar
Insert into table name values (value 1, value 2,....)
We can also specify the columns to which you want to insert data:
INSERT INTO table_name (column 1, column 2,...) VALUES (value 1, value 2,....)
Now look at the insert instance
Insert into Tbl_name (col1,col2) values ( );
This is to save a record, if I have to operate more than one
The code is as follows |
Copy Code |
$a = 1; $b = 1; while (5 == $a) { $sql = "INSERT into Tbl_name (col1,col2) VALUES ($a,$b)"; MySQL Tutorial _query($sql); $a++; $b++; } |
This method is very efficient, if it is 1 trillion times, it will be time-consuming. Here's another way to save multiple records using INSERT INTO
The code is as follows |
Copy Code |
Insert into ' usertable ' (' user_id ', ' user_name ') Values (1, ' DSF ') , (2, ' fgy ') , (3, ' Faad '); |
Improve the While
The code is as follows |
Copy Code |
$a = 1 ;
while ( 5 == $a )
{
if ( 1 == $a )
$sql = "INSERT into Tbl_name (col1,col2) VALUES ($a,$b)" ;
Else
$sql .= ", ($a,$b)" ;
$a ++;
$b ++;
}
mysql_query ( $sql ) ;
|