This website uses cookies in order to offer you the most relevant information and services online. Please accept cookies for optimal performance.
Learn More

Export Records from MySQL Database Table to Excel Sheet using PHP

Aug 31, 2016

In this article, we shall guide you how to export records from a MySQL database table to an excel spreadsheet using PHP.

Step 1: Connect the Database

Use the following code to connect to the database.

$sDBUser = 'XXXX'; //Database Username
$sDBPwd = 'XXXX'; //Database Password
$sDBName = 'XXXX'; //Database Name

$con = mysqli_connect("localhost",$sDBUser,$sDBPwd,$sDBName); //Open a connection to a MySQL Server

Step 2: Create a Function to Export Records

Use the following php code in your class file to export records.

function exportRecords()

PHP Application Framework
Batoi Framework is a PHP application framework with an Integrated Development Environment for Next Generation Apps and Services on the Cloud.
Create your web application without worrying about small things.
Give your feedback to improve the article

Need our assistance? We are available with you.

Existing Customer?
Get Support
Talk To Consultant?
Get An Appointment
Contact Us

Batoi global offices and contact details

Stay Connected

Join our community, newsletters, and social media.