Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts

    mysql_affected_rows returning -1 instead of 0?

    I have a script that updates the availability flag on data tables whenever availability is altered, before doing this I wrote a script to process all the availability of all properties. Now I want to use this script to periodically check that the availability is up-to-date - ie that there are no other scripts changing availability that we didn't know about/forgot.

    So my idea was to add up the results of mysql_affected_rows. If it was 0 that means the availability was still up-to-date. But it came to -1888

    My calls look like
    PHP Code:
    mysql_query('update owners_pricing_regular set available = 1 where pid='.$row['pid'].' and month = "'.$month.'" and year = "'.$row['year'].'"') or die(mysql_error());
    $affected_rows += mysql_affected_rows(); 
    Now mysql_affected_rows should return -1 if the query fails but the script should die if the query fails, so I would expect it to return 0 if the scripts are working.

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    PHP Code:
    $ranquery mysql_query('update owners_pricing_regular set available = 1 where pid='.$row['pid'].' and month = "'.$month.'" and year = "'.$row['year'].'"') or die(mysql_error());
    $affected_rows += mysql_affected_rows($ranquery); 
    off top of head and with a 4 alarm hangover
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    mysql_affected_rows() doesn't take a resource as an argument - it takes a link identifier for your mysql connection, but it's not required. It automatically picks up the last link opened by mysql_connect().

    http://us3.php.net/manual/en/functio...ected-rows.php

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    If I recall correctly, there doesn't need to be a matching record in the DB for that update to run successfully. If there isn't a match, there merely won't be an update, hence you'll be deducting one each time there is no match. Is that code within a loop?
    Last edited by MattF; 09-19-2009 at 08:24 PM.

  • #5
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://us3.php.net/manual/en/functio...ected-rows.php
    as u mentioned already.
    update wont return negative values right?
    So wat could be wrong?
    Last edited by ilight; 09-19-2009 at 09:29 PM.


  •  

    Posting Permissions

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