Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 658731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:57:57+00:00 2026-05-13T22:57:57+00:00

I have an array which has the contents as the result of an sql

  • 0

I have an array which has the contents as the result of an sql query.
I have been able to convert them into a CSV as well in the below format

2; Testing; IPTV; 9886784; 50061; 28/2/10 09:30:01 AM; 
3; Testing; IPTV; 9886784; 50061; 1/3/10 09:30:01 AM;
4; Testing; IPTV; 9886784; 50061; 2/3/10 09:30:01 AM;
5; Testing; IPTV; 9886784; 50061; 2/3/10 09:30:01 AM;

Now I would like to put this value into a .csv file and save it a particular location.

How can I do the above using php?

Kindly help as I am new to php

Kartik

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:57:58+00:00Added an answer on May 13, 2026 at 10:57 pm

    when $data contains your data to be written in a file, then do the following:

    <?php
       $filename = "mydata.csv";
       $handle = fopen($filename, "w");
       fwrite($handle, $data);
       fclose($handle);
    ?>
    

    the second fopen parameter defines, how to open the file. the following values are available:

    ‘r’ Open for reading only; place the file pointer at the beginning of the file.
    ‘r+’ Open for reading and writing; place the file pointer at the beginning of the file.
    ‘w’ Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
    ‘w+’ Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
    ‘a’ Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
    ‘a+’ Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
    ‘x’ Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
    ‘x+’ Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which has many values in it . I just wanted
I have created 4 buttons via Interface Builder. I have an array which has
I have an int array which has no elements and I'm trying to check
I have an array Items which has 10 elements. I need to remove the
I have an array called: $fragment = array($fragment); Which has the following three values:
I have a C++ code which has 3 array declarations. float A[NUM]; float B[NUM];
I have a file test.txt which has an array: array = [3,5,6,7,9,6,4,3,2,1,3,4,5,6,7,8,5,3,3,44,5,6,6,7] Now what
I'm using ASP.NET MVC and have a model which has an image (byte array)
I have a folder which has many files. Files are continually being dropped into
I have a struct which has several arrays within it. The arrays have type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.