Send Yun sensor data to MySQL on external server

Are the first 3 blocks of code just for setting up the database and installing PHP on the Linux or do they form part of some code I have to use constantly?

Is the. 4th section the file called db.php?

Sorry for being such a n00b I'm just trying to work out where to begin with this.