SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Ireland
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Number of rows that UPDATE returns

    Hi,

    I am setting up a scheduled PHP script to run every night.
    It UPDATEs a table like

    "UPDATE table SET active=0 WHERE to_days(date) < to_days(now() -interval 60 day)";

    ie. deactivate the rows that are older than 60 days.

    My problem is that I wish an email to be sent informing the recipient how many rows were changed - and possibly to put this figure into a table for future stats.

    The MySQL manual says
    UPDATE returns the number of rows that were actually changed. In MySQL Version 3.22 or later, the C API function mysql_info() returns the number of rows that were matched and updated and the number of warnings that occurred during the UPDATE.
    but I can't find a PHP way to get this number.

    Thanks for any help

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Ireland
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    More...

    To add to that, I know that when one performs an UPDATE query to the MySQL command line one gets for eg.

    Query OK, 56 rows affected (0.01 sec)

    But I mean to have this script running as a cron job. I'd like to get a handle on this number when the script runs. Does it have a $name?

    Many thanks,
    Elvin

  3. #3
    SitePoint Enthusiast numeropi's Avatar
    Join Date
    Apr 2001
    Location
    somewhere between 3.14 and 3.15
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you're looking for is the function mysql_affected_rows(). If the output of running the query manually was

    Query OK, 56 rows affected (0.01 sec)
    then mysql_affected_rows() would return 56
    No más enlaces rotos en el correo: EnlaceBreve.com
    Tu bitácora en castellano: BitacoraFacil.com

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Ireland
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks numeropi!


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
  •