At 09:15 20/08/2008, you wrote:

Message-Id: <[EMAIL PROTECTED]>
From: Amy Gibbs <[EMAIL PROTECTED]>
Date: Wed, 20 Aug 2008 09:08:42 +0100

I've managed to connect to my database, and run a select query, but
now I need to run an UPDATE query and it just doesn't seem to take
effect.


Things I'd try or check presuming the DB file it exists and returns rows from the SELECT :

(1) Ensure the SQLite DB file is not set to read-only in the filesystem, which will prevent UPDATE (2) Echo out the $sql line below on each iteration, to ensure it contains what you intend, and not unclosed quotes
(3) Set $sesdb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Step 3 should make your code barf when it can't execute a query and immediately indicate the problem. For some reason, PDO seems to default to silent errors at least when using the SQLite interface

HTH
Cheers - Neil


$sesdb = new PDO('sqlite:file.sqlite3');

$query="SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE
ZCategory != 14";

$statement= $sesdb->query($query);
$result=$statement->fetchAll();

foreach ($result as $product) {
$prodname=$product[0];
$prodqty = $product[1];
$prodid=$product[2];

$sql = "UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='".$prodid."'";

$sesdb->exec($sql);

}

[/code]



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to