Pages

Friday, December 23, 2011

Tutorial: How to MYSQL Insert, Update, Select, and Delete Data Using PHP

Assuming we have database mydatabase and table user:











First, before we execute some sql script we must connect to our database.

The PHP code:












How to INSERT data?

The PHP code:



The Result:


How to UPDATE data?

The PHP code:









The result:



How to SELECT data?


Assuming that we have this table:








In PHP, we can actually select the first row of data or we can also select multiple rows in the database.


Selecting first row only:

The PHP code:









The result:







Selecting multiple rows:

The PHP code:

 

 The Result:

 

How to DELETE data?

The PHP code:








The result:









To learn the basic of PHP programming such as how to run PHP files and configuring your server, try to read here. Happy coding!