PHP do not provide special functions for data operation, so you should follow MySQL syntax orders. In order to do the data operation by using PHP, so here is the sequence as follow:
- Connection to database
- Declare a variable string that contains of the next MySQL syntax order
- Run the MySQL syntax by using of mysql_query() function. If the syntax will produce the next output, declaration one variable to accommodate the result
- Take the result of the run MySQL syntax by using the functions of mysql_fetch_array(), mysql_fetch_row(), mysql_num_rows, etc. It depends to the output wanted format
Inserting Data
Insert data into database, use the syntax: INSERT INTO nam_table (field1,field2,…) VALUES (‘data1′,’data2′,…)If the field parameter does not declare, the amount of the inserting data must have the same as the amount of the table field.Example:<?php //the example of inserting data //data_insert.php mysql_connect("localhost","root","");//database connection mysql_select_db("employees"); $order = "INSERT INTO data_employees (name, address) VALUES ('H.R. Dian', 'Jl. Raya Baru KOTABARU')"; //inserting data order //declare in the order variable $result = mysql_query($order); if($result){ echo("<br>Input data is succeed"); }else{ echo("<br>Input data is fail"); } ?>Output:If you see through phpmyadmin
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment