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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:59:09+00:00 2026-05-10T13:59:09+00:00

I’ve been trying to use SQLite with the PDO wrapper in PHP with mixed

  • 0

I’ve been trying to use SQLite with the PDO wrapper in PHP with mixed success. I can read from the database fine, but none of my updates are being committed to the database when I view the page in the browser. Curiously, running the script from my shell does update the database. I suspected file permissions as the culprit, but even with the database providing full access (chmod 777) the problem persists. Should I try changing the file owner? If so, what to?

By the way, my machine is the standard Mac OS X Leopard install with PHP activated.

@Tom Martin

Thank you for your reply. I just ran your code and it looks like PHP runs as user _www. I then tried chowning the database to be owned by _www, but that didn’t work either.

I should also note that PDO’s errorInfo function doesn’t indicate an error took place. Could this be a setting with PDO somehow opening the database for read-only? I’ve heard that SQLite performs write locks on the entire file. Is it possible that the database is locked by something else preventing the write?

I’ve decided to include the code in question. This is going to be more or less a port of Grant’s script to PHP. So far it’s just the Questions section:

<?php  $db = new PDO('sqlite:test.db');  $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://stackoverflow.com/users/658/kyle'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIE, 'shhsecret=1293706652'); $page = curl_exec($ch);  preg_match('/summarycount'>.*?([,\d]+)<\/div>.*?Reputation/s', $page, $rep); $rep = preg_replace('/,/', '', $rep[1]);  preg_match('/iv class='summarycount'.{10,60} (\d+)<\/d.{10,140}Badges/s', $page, $badge); $badge = $badge[1];  $qreg = '/question-summary narrow.*?vote-count-post'><strong.*?>(-?\d*).*?\/questions\/(\d*).*?>(.*?)<\/a>/s'; preg_match_all($qreg, $page, $questions, PREG_SET_ORDER);  $areg = '/(answer-summary'><a href='\/questions\/(\d*).*?votes.*?>(-?\d+).*?href.*?>(.*?)<.a)/s'; preg_match_all($areg, $page, $answers, PREG_SET_ORDER);  echo '<h3>Questions:</h3>\n'; echo '<table cellpadding=\'3\'>\n';  foreach ($questions as $q) {     $query = 'SELECT count(id), votes FROM Questions WHERE id = '.$q[2].' AND type=0;';     $dbitem = $db->query($query)->fetch(PDO::FETCH_ASSOC);     if ($dbitem['count(id)'] > 0)     {         $lastQ = $q[1] - $dbitem['votes'];         if ($lastQ == 0)         {             $lastQ = '';         }         $query = 'UPDATE Questions SET votes = '$q[1]' WHERE id = '$q[2]'';         $db->exec($query);     }     else     {         $query = 'INSERT INTO Questions VALUES('$q[3]', '$q[1]', 0, '$q[2]')';         echo '$query\n';         $db->exec($query);         $lastQ = '(NEW)';     }     echo '<tr><td>$lastQ</td><td align=\'right\'>$q[1]</td><td>$q[3]</td></tr>\n'; }  echo '</table>';  ?> 
  • 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. 2026-05-10T13:59:09+00:00Added an answer on May 10, 2026 at 1:59 pm

    Kyle, in order for PDO/Sqlite to work you need write permission to directory where your database resides.

    Also, I see you perform multiple selects in loop. This may be ok if you are building something small and not heavy loaded. Otherwise I’d suggest building single query that returns multiple rows and process them in separate loop.

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

Sidebar

Ask A Question

Stats

  • Questions 153k
  • Answers 153k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If it really has to be as fast as possible,… May 12, 2026 at 10:18 am
  • Editorial Team
    Editorial Team added an answer One more vote for stored procedures in this case. What… May 12, 2026 at 10:18 am
  • Editorial Team
    Editorial Team added an answer Have a look at Jackcess. Note that this doesn't support… May 12, 2026 at 10:18 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.