How to Convert SQL Database into Excel File (*.xlxs) in PHP
Submitted by Mr.Niemand03 on Tuesday, April 24, 2018 - 19:04.
Language
In this tutorial, we will convert sql to excel using PHP. This code will read all data from an SQL table then add it into an excel file using a class called "xlsxwriter.class.php". You can download the class using this link from Github
Things to do
You have to download and install XAMPP or any local server that run PHP scripts. In my case I used XAMPP as my local server, here's the download link for XAMPP server https://www.apachefriends.org/download.html. If you already installed a local server (XAMPP, WAMP, etc.), just ignore this step. I've included a SQL file in the downloadable of this tutorial. All you have to do is import the said file. If you have no idea on how to import, please visit nurhodelta_17's tutorial on How import .sql file to restore MySQL database. You should be able to create a database namedguessmynumber.
Database Connection
Include Main Class
Create array from Query Result
'integer',
'Question Clue'=>'string',
'Question Answer'=>'integer',
);
while ($datafromsql = mysqli_fetch_assoc($user_query)) {
$rows[] = $datafromsql;
}
//secret code here. To view code, click "Download Code" Button below.
?>
Download Excel File
Tutorial done. I hope that this simple tutorial helps you. Enjoy Coding!!Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Comments
Add new comment
- Add new comment
- 851 views