Excuse me for asking again today, but i see no error in the following code, yes no isertion or update happens into the database:

try:
# locate the ID of the page's URL
cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
data = cur.fetchone()           #URL is unique, so should only be one
                
if not data:
        #first time for page; primary key is automatic, hit is defaulted
        cur.execute('''INSERT INTO counters (url) VALUES (%s)''', page )
                        cID = cur.lastrowid             #get the primary key 
value of the new added record
else:
        #found the page, save primary key and use it to issue hit UPDATE
        cID = data[0]
        cur.execute('''UPDATE counters SET hits = hits + 1 WHERE ID = %s''', 
cID )


When this code runs i check instantly my database via PHPMyAdmin and i see that it was left intact.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to