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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:14:00+00:00 2026-06-09T21:14:00+00:00

I’m trying to use SQLite3 in PHP, and everithing was fine until I needed

  • 0

I’m trying to use SQLite3 in PHP, and everithing was fine until I needed to perform an UPDATE.
I supose I miss a COMMIT, but I don’t find the way on how to do it.

My code is:

$respostes = $_POST['respostes'];
$return = array();

$conn = new SQLite3( '/home/pi/boxberry/boxberry.db', SQLITE3_OPEN_READWRITE );

$res = $conn->query( 'SELECT numero, resposta FROM preguntes WHERE NOT correcta' );
while( $resposta = $res->fetchArray( SQLITE3_ASSOC ) )
{
    if( strstr( strtolower( $respostes ), strtolower( $resposta['resposta'] ) ) !== FALSE )
    {
        $conn->exec( 'UPDATE preguntes SET correcta = 1 WHERE numero = ' . $resposta['numero'] );
        $return['canvis'] = $conn->changes();
        $conn->exec( 'COMMIT' );
        $res = $conn->query( 'SELECT correcta FROM preguntes WHERE numero = ' . $resposta['numero'] );
        $tmp = $res->fetchArray( SQLITE3_ASSOC );
        $return['tmp'] = $tmp['correcta'];
    }
}

.... more stuff ...

echo json_encode( $return );

What I want is to read all the questions from the database, and compare the answers from the resposta column with the answers within the $respostes variable received by POST. That also works fine.
Then, if the answer is correct, I need to put this correctness to the database, setting the correcta column for this row to 1.
If I show the query and then I put it on the SQLite3 console it works properly, but when I recheck it on PHP it keeps being 0, even when $conn->changes() shows that the UPDATE affected 1 row.

I checked everithing I can figure, the boxberry.db file is readable and writable by any user, I tried oppening it with SQLITE3_OPEN_READWRITE that should be as default, I tried to add an execution of a COMMIT, or even put it in the same exec line sepparating both with semicolons… No error is thrown, but the values doesn’t change.

Using SQLite with Python I found that I need to COMMIT after the UPDATE, but I can’t find the way to do it in PHP.

This script returns something like:
{“canvis”:1,”tmp”:0}
That means it should be 1 change, but then the value in the database is still 0 when should be 1.

  • 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-09T21:14:01+00:00Added an answer on June 9, 2026 at 9:14 pm

    You shouldn’t need to manually commit changes with the SQLite3 extension but you might need to make the directory that contains the database file writable (probably set it so that your webserver software has write-rights). Just making the database file itself writable is not always enough for SQLite.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

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.