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 9046891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:46:02+00:00 2026-06-16T11:46:02+00:00

Scenario: I am exporting a table Named Registration from access database and writing into

  • 0

Scenario:

I am exporting a table Named “Registration” from access database and writing into a file named “isl.txt” in php using pdo. Fields separated by “,” and Records separated by “\\”(i know it should be “\n” for convenience but it cant take a new line in text file. Don’t know why !! so i have chosen “\\”)

Registration Table in Access:

Roll_Num,Course,Marks,Discipline,Session

0,CS-101,89,CS,Fall94

0,CS-102,70,CS,Fall94

0,CS-103,59,CS,Fall94

Code:

$fl = fopen('isl.txt', 'w');
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=D:\Islamabad.mdb;Uid=;Pwd=;");
$results = $db->query("select * from `Registration`");

while ($row = $results->fetch()) {

foreach ($row as $value) {
   $lastv = end($row);

    if ($value != $lastv){

        fwrite($fl, $value.",");
        }

}
 fwrite($fl, $value."\\");
}
 fclose($fl);

Output:

0,0,CS-101,CS-101,89,89,CS,CS,Fall94\0,0,CS-102,CS-102,70,70,CS,CS,Fall94\0,0,CS-103,CS-103,59,59,CS,CS,Fall94

Problem:

As u see, every single value of record is repeating two times. Please Check whats wrong with my code!!

  • 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-06-16T11:46:03+00:00Added an answer on June 16, 2026 at 11:46 am

    The repeating values are because you are not specifying a fetch_style in $results->fetch([fetch_style]). According to the manual – http://php.net/manual/en/pdostatement.fetch.php – when fetch_style is not specified, it defaults to value of PDO::ATTR_DEFAULT_FETCH_MODE (which defaults to PDO::FETCH_BOTH).

    PDO::FETCH_BOTH (default): returns an array indexed by both column
    name and 0-indexed column number as returned in your result set

    Try changing to –

    while ($row = $results->fetch(PDO::FETCH_ASSOC)) {
    

    OR

    while ($row = $results->fetch(PDO::FETCH_NUM)) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on exporting a managed solution from a dev environment into another, clean
Scenario : I'll try to put an analogy with the loan broker example from
Scenario first :- I'm using Entity Framework to do some queries, to build my
Scenario While using the Maven Ant Task artifact:deploy , I'm encountering the error java.lang.OutOfMemoryError:
So the scenario is this: I have a mySQL database on a local server
I have a table in SQL server database in which I am recording the
I have a scenario like this: I'm using interceptor to catch calls to a
I am unable to write a simple file to the iCloud container from my
I have a scenario where the unit of work is defined as: Update table
Imagine a scenario you have a text file with say 10000 rows in it

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.