how we can parse php code into CSV files??

I am working first time on CSV files. I want to fetch record or value which are coming from database in php. I want to fetch these all value in CSV file or excel spreadsheet. Please help me . How i can do this.Its very urgent for me.

<?php
/**
* EXAMPLE (iam_dsvdump)
*
* @author Ivn Ariel Melgrati <phpclasses@imelgrat.mailshell.com>
* @version 1.0
* @package iam_csvdump
*
* A class form performing a query dump and sending it to the browser or setting it or download.
* Requires PHP v 4.0+ and MySQL 3.23+
*
* Copyright (C) Ivn Ariel Melgrati <phpclasses@imelgrat.mailshell.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#####################################################################################################################
# Include the class #
#####################################################################################################################
require_once("iam_csvdump.php");
#####################################################################################################################
# Set the parameters: SQL Query, hostname, databasename, dbuser and password #
#####################################################################################################################
$dumpfile = new iam_csvdump;
#####################################################################################################################
# Call the CSV Dumping function and THAT'S IT!!!! A file named dump.csv is sent to the user for download #
#####################################################################################################################
if(!empty($_GET['type'])){
$dumpfile->dump("SELECT r.p_id as Id,r.p_name as ProductName,r.p_quality as Quality,r.stock as Stock,r.p_price as Price FROM `tbl_products` as r where r.status=1 ", "dump", "csv", "getthebe_Vegbest", "getthebe_Getbest", "C}71Z<l2@KK)", "localhost" );
}
//$dumpfile2->dump("SELECT r.salutation as Salutation,r.username as UserName, r.fname as firstname, r.lname as lastname ,r.email as Email ,r.customerid as customerid,r.organisation as Organisation,r.department as Department ,r.phone as phoneno,r.jobtitle as jobtitle ,r.city as city ,r.language as language ,r.state as state ,r.country as country ,r.pincode as pincode ,r.pobox as pobox ,r.fax as fax FROM `bio_users` as r ", "dump", "csv", "bitrane_biogen", "bitrane_biox", "9bio99", "mysql19.ixwebhosting.com" );
//$dumpfile->dump("SELECT * FROM `points_table_cal` as p,`temp_points` as t where p.p_id=t.pid_fk and points_total<=75", "dump", "csv", "opulentus", "root", "1234", "localhost" );
?>