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

  • Home
  • SEARCH
  • 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 8235321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:46:03+00:00 2026-06-07T18:46:03+00:00

$file_db = new PDO(‘sqlite:test.db’); if($file_db){ $result = $file_db->query(‘SELECT id FROM sample’); $encodable = array();

  • 0
$file_db = new PDO('sqlite:test.db');
if($file_db){
    $result = $file_db->query('SELECT id FROM sample');
    $encodable = array();
    while($obj = $result->fetch())
    {
        $encodable[] = $obj;
    }

    $encoded = json_encode($encodable);
    echo $encoded;
}else{
    die("unable to conenct to db");
}

I just want to output {"id":"1"} but it also gives me "0":"1". Does anyone know why?

Result:

[{"id":"1","0":"1"},{"id":"2","0":"2"},{"id":"3","0":"3"},{"id":"4","0":"4"},{"id":"5","0":"5"},{"id":"6","0":"6"},{"id":"7","0":"7"},{"id":"8","0":"8"},{"id":"9","0":"9"},{"id":"10","0":"10"},{"id":"11","0":"11"},{"id":"12","0":"12"},{"id":"13","0":"13"},{"id":"14","0":"14"}]
  • 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-07T18:46:05+00:00Added an answer on June 7, 2026 at 6:46 pm

    Is because of the way you are fetching the data with PDO. PDOStatement::fetch enables you to choose if you want an associative array, an indexed array and more. The default is to have both. Change it to that to have the behaviour you are expecting:

    while($obj = $result->fetch(PDO::FETCH_ASSOC))

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

Sidebar

Related Questions

UPDATED My latest code as follows: $file =sqlite:C:\New folder\\test.db; echo $file; $handle = new
I am new to the File::Slurp module, and on my first test with it,
I am able to retrieve information from a SQLite database in PHP, but not
I am new to Android development and would like to select data and pre-populate
I try to copy SQLite database from assets directory to access it later. But
I have a file.db (binary) that I can read from SQlite 3.exe, but I
I am new to android . I have an application working with SQLite DB.
I've been trying to use SQLite with the PDO wrapper in PHP with mixed
Greetings Overflowers, What is wrong with this PHP code: <?php define(DB_FILE, sqlite:database.sql); define(QUERY, INSERT
Please I am very new to PDO, rather a novice at PHP as well.

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.