Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP CSV File Export Using fputcsv()

<?php
$conn = mysqli_connect("localhost", "root", "test", "phppot_examples");

$filename = "toy_csv.csv";
$fp = fopen('php://output', 'w');

$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='phppot_examples' AND TABLE_NAME='toy'";
$result = mysqli_query($conn,$query);
while ($row = mysqli_fetch_row($result)) {
	$header[] = $row[0];
}	

header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
fputcsv($fp, $header);

$query = "SELECT * FROM toy";
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_row($result)) {
	fputcsv($fp, $row);
}
exit;
?>
Comment

PREVIOUS NEXT
Code Example
Php :: add column in existing table in laravel 
Php :: how to add new column in laravel migration 
Php :: php stmt prepare error 
Php :: proper permission webserver laravel 
Php :: array_map class method 
Php :: read csv php 
Php :: Fatal error: Uncaught ReflectionException: Class config does not exist in 
Php :: new line php 
Php :: How to get only year, month and day from timestamp in Laravel 
Php :: php append line to file 
Php :: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.9.1/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223 mac 
Php :: flutter form autadjust height 
Php :: laravel blade auth user 
Php :: laravel mixed content error 
Php :: oci_execute(): ORA-01810: format code appears twice in 
Php :: php artisan down 
Php :: remove first character from string laravel 
Php :: php validate date format 
Php :: how to check if PHP-FPM is running 
Php :: php foreach array 
Php :: check if url is https laravel 
Php :: carbon random future date 
Php :: php to int 
Php :: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) 
Php :: unable to locate package php8.1 ubuntu 
Php :: acf options page 
Php :: test curl php 
Php :: the action you have requested is not allowed. in codeigniter 
Php :: laravel join 
Php :: how to get auth user name in laravel 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =