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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:36:10+00:00 2026-05-15T18:36:10+00:00

I started trying to use sqlite to host small websites and on my own

  • 0

I started trying to use sqlite to host small websites and on my own personal server, I ran into a glich which kind of spoils the whole idea.

I have a very simple test example, on a two row table in a sqlite 2.x database, I am being hosted with 5.2.12, I have also tried with the PDO sqlite3 database, the problem is this. The “users” table, holds some information, the table is like this

fields(id,username,forename,surname,password)

There are two entries into the table, they are

entry(1,chris,Christopher,Thomas,123)
entry(2,adam,Adam,Tanner,456)

The problem is a bit strange, when I query the database like this:

query(“select * from users where id=2”)

I get the correct results, like this below:

entry(2,adam,Adam,Tanner,456)

When I request ALL the rows, like this query(“select * from users”) I get this:

entry(1,chris,Christopher,Tanner,456)
entry(2,adams,Adamstopher,Tanner,456)

Do you see what seems to have happened? The information in the second entry, is less characters than the first entry, so it seems to be just overwriting the data with the second entry, causing some corruption.

chris
adams<—- The s comes from chris

Christopher
Adamstopher <— The stopher comes from christopher


The code is very simple, this is what I run, I try direct sqlite_* calls on sqlite2 and then PDO on sqlite2 and sqlite3 versions of the same database, just to make sure there was any doubt.

(BTW: I added some simple html markup changes and things to make it all look better in the stackoverflow website, those changes aren’t in the original code, but they are just things like h1->p or wrapping things with <pre> to preserve the code formatting, etc).

<p>TEST 1 with direct sqlite_* calls</p>
<?php 
try{
    $connection = sqlite_open("../playground.sqlite",0666,$error);
    $handle = sqlite_query("select * from users",$connection);

    $numResults = sqlite_num_rows($handle);

    for($a=0;$a<$numResults;$a++){
        print("<pre>".print_r(sqlite_fetch_array($handle,SQLITE_ASSOC),true)."</pre>");    
    }

}catch(Exception $e){
    die("EXCEPTION OCCURED: '$error'");
}
?>
<p>PDO TEST: SQLITE 2.x</p>
<?php    
    $connection = new PDO('sqlite2:../playground.sqlite');
    $handle = $connection->query("SELECT * FROM users");

    if($handle){
        $result = $handle->fetchAll(PDO::FETCH_ASSOC);
        print("<pre>".print_r($result,true)."</pre>");
    }else{
        var_dump($connection->errorInfo());
        print("query returned negatively");
    }
?>
<p>PDO TEST: SQLITE 3.x</p>
<?php    
    $connection = new PDO('sqlite:../playground.sqlite3');
    $handle = $connection->query("SELECT * FROM users");

    if($handle){
        $result = $handle->fetchAll(PDO::FETCH_ASSOC);
        print("<pre>".print_r($result,true)."</pre>");
    }else{
        var_dump($connection->errorInfo());
        print("query returned negatively");
    }
?>

The output from running this code is:

TEST 1 with direct sqlite_* calls
Array
(
    [id] => 1
    [username] => chris
    [forename] => Christopher
    [surname] => Thomas
    [password] => 123
)

Array
(
    [id] => 2
    [username] => adams
    [forename] => Adamstopher
    [surname] => Tanner
    [password] => 456
)

PDO TEST: SQLITE 2.x
Array
(
    [0] => Array
        (
            [id] => 1
            [username] => chris
            [forename] => Christopher
            [surname] => Thomas
            [password] => 123
        )

    [1] => Array
        (
            [id] => 2
            [username] => adams
            [forename] => Adamstopher
            [surname] => Tanner
            [password] => 456
        )

)

PDO TEST: SQLITE 3.x
Array
(
    [0] => Array
        (
            [id] => 1
            [username] => chris
            [forename] => Christopher
            [surname] => Thomas
            [password] => 123
        )

    [1] => Array
        (
            [id] => 2
            [username] => adams
            [forename] => Adamstopher
            [surname] => Tanner
            [password] => 456
        )
)

If you know why this happens, thanks for letting me know!

  • 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-15T18:36:11+00:00Added an answer on May 15, 2026 at 6:36 pm
    <?php
    echo PHP_VERSION, ' ', PHP_OS, ' ', PHP_SAPI, "\n";
    
    $pdo = new PDO('sqlite:sotest.sqlite'); 
    $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    
    $pdo->exec('DROP TABLE IF EXISTS users');
    $pdo->exec('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY ASC, username,forename,surname,password)');
    $pdo->exec("INSERT INTO users (id,username,forename,surname,password) VALUES (1,'chris','Christopher','Thomas',123)");
    $pdo->exec("INSERT INTO users (id,username,forename,surname,password) VALUES (2,'adam','Adam','Tanner',456)");
    
    $rows = $pdo->query("SELECT Length(forename) as cForename, Length(surname) as cSurname, * FROM users")->fetchAll(PDO::FETCH_ASSOC);
    print_r($rows);
    

    on my machine prints

    5.3.2 WINNT cli
    Array
    (
        [0] => Array
            (
                [cForename] => 11
                [cSurname] => 6
                [id] => 1
                [username] => chris
                [forename] => Christopher
                [surname] => Thomas
                [password] => 123
            )
    
        [1] => Array
            (
                [cForename] => 4
                [cSurname] => 6
                [id] => 2
                [username] => adam
                [forename] => Adam
                [surname] => Tanner
                [password] => 456
            )
    
    )
    

    Can you reproduce the erroneous behaviour with this code on your 5.2.x server?

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

Sidebar

Related Questions

I've recently started to use SQLite and began to integrate it into a C#
I've just started programming, therefore I'm kinda noob. I'm trying to use python to
I have recently started to use Twitter Bootstrap and trying to understand how it
I started by trying to store strings in sqlite using python, and got the
I'm just digging a bit into Haskell and I started by trying to compute
Trying to use Database Designer in VS2010 for the first time. I started adding
I've just started trying to use Solr, and already I think that I'm attempting
Just started writing java / android and I am trying to use android.widget.VideoView. I
I'm trying to use gdb to debug a shared library when stepping into the
I'm trying to use the NetBeans 7.1 profiler to profile a program which runs

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.