1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

MySQL WHERE less than

Discussion in 'MySQL' started by Tony Brar, Jan 14, 2013.

  1. #1
    Hi guys,

    When I try to run the following script (and yes, the connection works):
    
    $hourago = time()-3600;$tokendel = $dbh->exec("DELETE * FROM tokens WHERE setdate < '$hourago'");
    PHP:
    It gives me this error:
    Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM tokens WHERE setdate \&lt; '1358193601'' at line 1' in /home/content/42/9125042/html/resources/tokenclear.php:10
    Why doesn't my script work?

    Thanks,
    -Tony
     
    Tony Brar, Jan 14, 2013 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Your script is escaping the less than symbol. < = \&lt;

    I would try something like:

    $statement = $dbh->prepare('DELETE * FROM tokens WHERE setdate < :hourago');

    $statement->execute(array(':hourago' => $hourago));
     
    jestep, Jan 14, 2013 IP
  3. Tony Brar

    Tony Brar Active Member

    Messages:
    220
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #3
    I tried it, but got the same result:
    Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM tokens WHERE setdate &lt; '1358209803'' at line 1' in /home/content/42/9125042/html/resources/tokenclear.php:11

    -Tony
     
    Tony Brar, Jan 14, 2013 IP
  4. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #4
    Do we need * on DELETE statement?
     
    artus.systems, Jan 15, 2013 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    Totally overlooked that.
     
    jestep, Jan 15, 2013 IP
  6. ronssel

    ronssel Guest

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #6
    ahaha........
     
    ronssel, Jan 15, 2013 IP
  7. Tony Brar

    Tony Brar Active Member

    Messages:
    220
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #7
    Well, I want to delete the entire row.
    Should I not use *?

    Thanks,
    -Tony
     
    Tony Brar, Jan 15, 2013 IP
  8. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #8
    DELETE implies that the identified row will be deleted.
     
    jestep, Jan 15, 2013 IP
  9. Tony Brar

    Tony Brar Active Member

    Messages:
    220
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #9
    I'll take out the *, but I don't think it will do anything.
    The problem seems to be the < sign being turned into &lt.
    How can I stop that from happening?

    Thanks,
    -Tony
     
    Tony Brar, Jan 15, 2013 IP