FAQ Database Discussion Community


Currently my code exports data to a CSV file, and stores it on the server. But I want it to download the file. How do I do this?

php,csv,download,export,fputcsv
I tried doing it with headers in the past, but it either downloaded an empty CSV file or the PHP file itself. <?php $database = new PDO('mysql:host=localhost;dbname=DB_Name', "root", ""); $sql = "SELECT Card_ID, Card_UID, Card_Type FROM cards"; $stmt = $database->prepare($sql); $stmt->execute(); $filename = 'MyCSVFile-'.date('Y-m-d').'.csv'; $data = fopen($filename, 'w'); while ($row...

php fputcsv is trims the string value while writing to file

php,file,fputcsv
I don't know this question is asked or not. I didn't get his in suggestion. I'm trying to write some data from database to an csv file. I'm using fputcsv function. I'm using following code : $fh = @fopen($fileName, 'w+'); $writeText['sku'] = $somevalue $writeText['attribute_set'] = $somevalue $writeText['type'] = $somevalue $writeText['default_catalogue_link']=...

export mysql query array using fputcsv

php,mysql,arrays,csv,fputcsv
I am trying to export the results of a sql query to CSV using fputcsv however keep getting the error "fputcsv() expects parameter 2 to be array, string given". I followed the answer given here - Query mysql and export data as CSV in PHP - but it throws the...

Unable to save data in each category - PHP CSV

php,mysql,csv,fputcsv
I have a CSV file from which I want to insert data in the database. There are some scenrios involved in it. Like, If category exists in the database, the script simple insert all video of that categody in the database without inserting the category in the category table. And...

How to programatically HTTP POST a CSV file directly from an array in PHP?

php,csv,post,curl,fputcsv
I'm contributing data to the opencellid.org website. They have several API options to submit data but the only bulk method requires an HTTP POST file upload with the API key as a POST field. Formats acceptable are CSV, JSON and CLF3. I store the data in an SQL database for...

why fputcsv produce extra blank column in csv

php,csv,fputcsv
I am trying to remove unnecessary column from my csv. What i do is read from current csv and use fputcsv to produce a new one. However, the data is mess up because fputcsv add extra blank column just before $data[21]. Below is my code $file_path = 'test.csv'; $file_output =...

PHP exporting data to CSV in multiple sheets

php,phpexcel,fputcsv
Each day I run a cron where it finds data that has not been pulled/exported yet (via a column "exported" that contains a boolean) and this works fine. However, now I'd like to do a loop for each of the results and stick them in to the exported CSV in...

How to write an array as csv file content using php?

php,csv,fopen,fputcsv
I am importing a CSV file into my site which contain Hebrew language.While opening the CSV file in the notepad, the Hebrew language content are not enclosed by the quotes. The content which is not in quotes are not read in my site. During the time of uploading this csv...

Create CSV from multidimensional array with fputcsv

php,arrays,string,multidimensional-array,fputcsv
I'm trying to get a multidimensional array into a csv file. data in the array is as such: Array ( [0] => Array ( [product_id] => 1111 [name] => Alcatel One Touch Idol 2 [keyword] => alcatel-one-touch-idol-2 [options] => Array ( [0] => Array ( [price] => 54.0000 ) [1]...