SQLite/PHP read-only? -


i've been trying use sqlite pdo wrapper in php mixed success. can read database fine, none of updates being committed database when view page in browser. curiously, running script shell update database. suspected file permissions culprit, database providing full access (chmod 777) problem persists. should try changing file owner? if so, to?

by way, machine standard mac os x leopard install php activated.

@tom martin

thank reply. ran code , looks php runs user _www. tried chowning database owned _www, didn't work either.

i should note pdo's errorinfo function doesn't indicate error took place. setting pdo somehow opening database read-only? i've heard sqlite performs write locks on entire file. possible database locked else preventing write?

i've decided include code in question. going more or less port of grant's script php. far it's 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 $q) {     $query = 'select count(id), votes questions id = '.$q[2].' , 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]' id = '$q[2]'";         $db->exec($query);     }     else     {         $query = "insert 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>";  ?> 

kyle, in order pdo/sqlite work need write permission directory database resides.

also, see perform multiple selects in loop. may ok if building small , not heavy loaded. otherwise i'd suggest building single query returns multiple rows , process them in separate loop.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -