Create CSV File Using PHP MySqli

Create comma seprated file using fwrite php function using with mysql query. It is very easy way to create csv file.

<?php
$con =  new mysqli("127.0.0.1","root","cx(ymc@!","demodb");
if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
}
$sql = "SELECT phoneNo_int,fName_vch,lName_vch FROM users";
$result = $con->query($sql);
$bufferDATA = "";
$exportPath = $_SERVER["DOCUMENT_ROOT"]."/demo/uploads";
$inpFileName = "users.csv";
$bufferDATA = "Contact No,First Name,Last Name".CHR(13);
/*If file already found delete it from directory*/
try {
    if(file_exists($exportPath."/".$inpFileName)) {
        unlink($exportPath."/".$inpFileName);
    }
}catch(Exception $e){
    echo $e->getMessage();
} 
............
............
............
 
More details visit :
https://www.elearn99.com/programming/create-comma-seprated-file-php/258/ 
 

Comments

Popular posts from this blog

Login with facebook using coldfusion

Create CSV file in Coldfusion Using CFFile

Get Previous One Day Data in Sql Server