473,378 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

SQLite3 and PHP

Jon
Hi,

I'm having some trouble trying to get DELETE to work with SQLITE3 and
PHP and was wondering if anyone could be of some assistance?

I have verified that it is set up correctly and I'm able to insert /
create / select from tables but I'm unable to delete specific entries.

Given the following 2 tables:

Table A Table B
Name Cost Name Cost
A 1 D
3
B 2 E
5
C 3 F
7

how would I delete entries with the same cost?

my current code is:

<?php
function deleteRel($year) {

$db_file = "/../".$year.".sqlite3";
try{
$dbHandle = new PDO('sqlite:'.$_SERVER['DOCUMENT_ROOT'].$db_file);
}catch ( PDOException $exception ){
die($exception->getMessage());
}

$sqlDeleteVal = sprintf("DELETE table_1 FROM table_1, table_2 WHERE
table_1.cost = table_2.cost");

}
$year = 2010;
deleteRel($year);
?>

Please note that I do not wish to use UNIQUE since this is just a
simplification of what I am trying to achieve.

Thanks for your responses!

Apr 23 '07 #1
5 1944
Jon schrieb:
$sqlDeleteVal = sprintf("DELETE table_1 FROM table_1, table_2 WHERE
table_1.cost = table_2.cost");
Wrong SQL syntax:
http://sqlite.org/lang_delete.html

OLLi

--
"You see, Mr. President: The worlds hates America. And for good reason.
(I wont bother going into details)"
[24 319]
Apr 23 '07 #2
Jon
On Apr 23, 6:45 pm, Oliver Grätz <oliver.gra...@gmx.dewrote:
Jon schrieb:
$sqlDeleteVal = sprintf("DELETE table_1 FROM table_1, table_2 WHERE
table_1.cost = table_2.cost");

Wrong SQL syntax:http://sqlite.org/lang_delete.html

OLLi

--
"You see, Mr. President: The worlds hates America. And for good reason.
(I wont bother going into details)"
[24 319]
Thanks OLLi, yes I updated but forgot to post: this is the current
fixed syntax.
$sqlDeleteVal = "DELETE * FROM table_1, table_2 WHERE
round(table_1.payment,2) = round(table_2.payment,2)*-1";

With switching DELETE with SELECT, it yields exactly the results I
want to delete. However, with the above fix to my code, no deletion
occurs. I'm very confused!

Apr 24 '07 #3
Jon
On Apr 23, 6:45 pm, Oliver Grätz <oliver.gra...@gmx.dewrote:
Jon schrieb:
$sqlDeleteVal = sprintf("DELETE table_1 FROM table_1, table_2 WHERE
table_1.cost = table_2.cost");

Wrong SQL syntax:http://sqlite.org/lang_delete.html

OLLi

--
"You see, Mr. President: The worlds hates America. And for good reason.
(I wont bother going into details)"
[24 319]

syntax is fixed.

"DELETE * FROM table_1, table_2 WHERE round(table_1.payment,2) =
round(table_2.payment,2)*-1";

Checked it by replacing DELETE with SELECT it and it shows the items I
wanted DELETED but DELETE is still not working. Doesn't do anything
but no warnings/errors.

Apr 24 '07 #4
Jon schrieb:
syntax is fixed.
No it isn't. DELETE takes no column argument since it only deletes
complete rows.

"DELETE * FROM table_1, table_2 WHERE round(table_1.payment,2) =
round(table_2.payment,2)*-1";
Try "DELETE FROM".
OLLi

--
Krach macht das Board nur beim Runterfallen - die Northbridge ist passiv
gekühlt.
[Mainboardtest auf hartware.de]
Apr 29 '07 #5
Jon <yu*****@gmail.comwrote:
>Hi,

I'm having some trouble trying to get DELETE to work with SQLITE3 and
PHP and was wondering if anyone could be of some assistance?

I have verified that it is set up correctly and I'm able to insert /
create / select from tables but I'm unable to delete specific entries.

Given the following 2 tables:

Table A Table B
Name Cost Name Cost
A 1 D
3
B 2 E
5
C 3 F
7

how would I delete entries with the same cost?
You want to delete from BOTH tables?

Deleting from one table is easy:

DELETE FROM tablea WHERE cost IN
(SELECT cost FROM tableb);

To delete from both tables, you'll have to copy the costs that are
duplicated into a temporary table, and then use that in a subselect. Or,
grab the SELECT results into a variable and construct the DELETE yourself.

SELECT tablea.cost FROM tablea,tableb WHERE tablea.cost=tableb.cost;
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Apr 30 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Harold Shore | last post by:
From the release notes I read that "If you're compiling the Python source yourself, note that the source tree doesn't include the SQLite code, only the wrapper module. You'll need to have the...
2
by: John Machin | last post by:
Apologies in advance if this is a bit bloggy, but I'd like to get comments on whether I've lost the plot (or, more likely, failed to acquire it) before I start reporting bugs etc. From "What's...
66
by: mensanator | last post by:
Probably just me. I've only been using Access and SQL Server for 12 years, so I'm sure my opinions don't count for anything. I was, nevertheless, looking forward to Sqlite3. And now that gmpy...
2
by: Josh | last post by:
Hi, I'm running into a problem when trying to create a view in my sqlite database in python. I think its a bug in the sqlite3 api that comes with python 2.5. This works as expected: conn =...
3
by: cjl | last post by:
P: I am using python 2.5.1 on windows. I have the following code: conn = sqlite3.connect('.\optiondata') c = conn.cursor() try: c.execute('''create table options (ssymbol text, strike real,...
4
by: Simon | last post by:
I installed the source code on unix for python 2.5.1. The install went mainly okay, except for some failures regarding: _ssl, _hashlib, _curses, _curses_panel. No errors regarding sqlite3....
0
by: Josh Ritter | last post by:
A number of our Windows customers have an issue with the sqlite3 module included with Python 2.5.1 We've tracked the problem down to the sqlite3.dll included with the Python 2.5.1 distrubtion. ...
3
by: milan_sanremo | last post by:
I have sqlite installed, but when I try to import sqlite3 I receive: Python 2.5.1 (r251:54863, Nov 3 2007, 02:54:36) on sunos5 Type "help", "copyright", "credits" or "license" for more...
0
by: Ben Lee | last post by:
hi folks -- a quick python and sqlite3 performance question. i find that inserting a million rows of in-memory data into an in-memory database via a single executemany() is about 30% slower...
15
by: Kurda Yon | last post by:
Hi, I try to "build" and "install" pysqlite? After I type "python setup.py build" I get a lot of error messages? The first error is "src/ connection.h:33:21: error: sqlite3.h: No such file or...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.