PHP practice 4


Program in PHP to connect to MySQL database, load data in table stores information of companies gives products for website online business


I. General

In this practice, I will talk the main of program to connect database. There is circumstance, programmer have to use PHP to program to connect MySQL database to load all information of companies gives products for website online business. This practice build the firstly base of programming database. It solves two problems: the first one is introduction MySQL database; the second one is programming to show up data from database. Of course, data of table stores information of companies will show up on web page like a menu. Companies will used to filter products.

II. Implement

1. Create database in MySQL

In dynamic web programming, the firstly we have to create database to stores all information relation to our website. It look like some relation database, table still store information. However, with SQL-Server we use application base to manage so MySQL in this situation we will use Web base to manage. It is same the real environment for deploy website project.

Step 1: start phpMyAdmin -> input the name of database into textbox after that click create new database. Choose utf8_unicode_ci and click create.

Step 2: create table by input name of table and number of column. However no worry, in MySQL you can modify all things of table so easy.

2. Create account to connect to database

Surely, your connection best in access to database, let is you use one account and privilege for that one. It look like deploy the real website project in place of using root account (default) in Wampserver or Xampserver.

3. Programming access to database

For easy to manage code after, we separated PHP code become mysource.php and store in source folder. In future, when you familiar with PHP programming you will be more creative, user more principles of object oriented programming… However in this situation try to get basic of database programming to make base for future.

I suggest sentence: “connecting to show up data”, “connecting to edit data”, “connecting to delete data”. Programming connect to database normally including two steps: step one is connect to database; step two is inserting, deleting, or editing data. So in case load data form table stores information become menu to show up on website, we create two function: the first one is connection; the second one is load data.

php practice 4 coding

4. Video for more details

Have fun, good luck.