SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2001
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php script from cron check

    Hi, i have php script which is outside web dir that deletes unconfirmed users from db when run via cron, could someone have quick look and check it is ok.

    thanks

    Code:
    #!/usr/bin/php -q
    <?php
      // cron job to delete inactive users older than 2 Days
      $db=mysql_connect('localhost','dbname','password');
      mysql_select_db('dbname',$db);
      $strSQL="DELETE FROM `PLD_USER` WHERE `EMAIL_CONFIRMED` = '0' AND `REGISTRATION_DATE` < (CURDATE() - INTERVAL 2 DAYS);"
    ?>

  2. #2
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Why don't you check it yourself? Copy the script
    PHP Code:
    <?php
      
    // cron job to delete inactive users older than 2 Days
      
    $db=mysql_connect('localhost','dbname','password');
      
    mysql_select_db('dbname',$db);
      
    $strSQL="DELETE FROM `PLD_USER` WHERE `EMAIL_CONFIRMED` = '0' AND `REGISTRATION_DATE` < (CURDATE() - INTERVAL 2 DAYS);"
    ?>
    to a page in the web directory and run it after adding a few test cases to the database that should be deleted. Then check the database. Presto! You're done!
    Denny Schlesinger
    web services

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,070
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    It doesn't actually perform the query, so I'd be surprised if anything happens when you run that script...

    Also, mysql_ is deprecated and it is recommended you switch to mysqli or PDO
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Member
    Join Date
    Apr 2013
    Location
    Oregon
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you need to test this independent of the cron job, and once its working go back and implement the cron job.

    Just make it into a php file, go to it in browser, and then check your DB for the changes. Fix until you see the changes you are supposed to see. Check yoru error_log file in root to see whats happening.

    The folks above are right, your current implementation is incomplete. It never actually executes the sql. Google for PDO examples.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •