Inserting Records In PHP

Inserting Records In PHP Here, you will how to insert a row of data.

INSERT INTO table VALUES ( value1 , value2 , … );

If a user wants to Inserting Records In PHP only some values, leaving NULLs or other default values in the remaining fields, use:

INSERT INTO table ( field1 , field2 , … ) VALUES ( value1 , value2 , … );

Though the first approach is compact, and perfectly valid if a user wants to populate all the fields in the row, the second approach is generally more flexible and readable.

To Inserting Records In PHP using your PHP script, a user needs to pass INSERT statements to MySQL via PDO in much the same way as you pass SELECT statements. If a user do not want to pass data from any PHP variables, then use the simple PDO::query() method.

Scroll to Top