PHP + SQLite - Issues with update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prashantprabhudesai
Forum Newbie
Posts: 1
Joined: Thu Oct 20, 2011 10:09 pm

PHP + SQLite - Issues with update

Post by prashantprabhudesai »

Hello,

I am running into some issues trying to update a column in a table in a SQLite database using PHP on Windows and was hoping could get some help on this mailer.

Here is the create and insert statement -

Code: Select all

CREATE TABLE SERVER (
	IPAddress varchar(100) not null unique primary key,
	Token varchar(100) unique
);

INSERT INTO SERVER (IPAddress, Token) VALUES
('192.168.1.100', '');
I am trying to update the Token field using the following code -

Code: Select all

$db = new SQLiteDatabase('db/reg.s3db');

$intoken = uniqid();

$db->query("update SERVER set Token = '$intoken'");

$res = $db->query("select * from SERVER");

$row = $res->fecth();

$outtoken = $row['Token'];

echo $outtoken;
After the script exits successfully I inspect the value in the Token column and its empty. But the echo statement in the snippet above prints the proper value.

Interestingly, if I error out the script with a syntax error or some such after the update but before it exits, the value shows up in the Token column.

Any idea what is happening here and I need to do here. Seems like there is some sort of flush that needs to happen which happens only if the script errors out.

Any help is appreciated.

Thanks,
Prashant.
Last edited by Benjamin on Fri Oct 21, 2011 2:22 am, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: PHP + SQLite - Issues with update

Post by nowaydown1 »

Not sure if it's related or not, but in your snippet, you have transposed letters for your fetch call. Presently you have:

Code: Select all

$row = $res->fecth();
Instead of:

Code: Select all

$row = $res->fetch();
Also, adding some error handling probably wouldn't hurt to see if your update query is failing or what:

http://www.php.net/manual/en/function.s ... -error.php
Post Reply