Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Posts
    364
    Plugin Contributions
    0

    help question How to Get Count from Last Delete Query - Row Affected?

    Greetings,

    I've created some custom code to delete some records via admin using the query factory class. It works, but don't know how to get a count of how many records were affected / deleted?

    I tried this, but it doesn't return any results...

    PHP Code:
    $del_sql 'My Delete Query';
    $del_results $db->Execute($del_sql);
    $count $del_results->RecordCount();
    echo 
    $count
    Suggestions?

    Thanks
    Experience is what you get when you don’t get what you want…

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,493
    Plugin Contributions
    88

    Default Re: How to Get Count from Last Delete Query - Row Affected?

    @kwright, thanks for making me go and look. This functionality really should be part of the Zen Cart queryFactory class to provide portability, but here's a snippet that will work only for Zen Cart v1.5.3 and later (since they use the mysqli form of database interface):
    Code:
    count = mysqli_affected_rows ($db->link);
    That should return the count of affected rows for the previous UPDATE, INSERT, REPLACE or DELETE query, per the function's documentation.

    Be sure to comment the heck out of that statement, just in case the built-in database engine changes again in the future!

  3. #3
    Join Date
    Nov 2004
    Posts
    364
    Plugin Contributions
    0

    Default Re: How to Get Count from Last Delete Query - Row Affected?

    Quote Originally Posted by lat9 View Post
    @kwright, thanks for making me go and look. This functionality really should be part of the Zen Cart queryFactory class to provide portability, but here's a snippet that will work only for Zen Cart v1.5.3 and later (since they use the mysqli form of database interface):
    Code:
    count = mysqli_affected_rows ($db->link);
    That should return the count of affected rows for the previous UPDATE, INSERT, REPLACE or DELETE query, per the function's documentation.

    Be sure to comment the heck out of that statement, just in case the built-in database engine changes again in the future!
    Thanks lat9,

    That did it!

    I too would agree that this would be very helpful to have integrated into the queryFactory class.
    Experience is what you get when you don’t get what you want…

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,493
    Plugin Contributions
    88

    Default Re: How to Get Count from Last Delete Query - Row Affected?

    Woo-hoo! Thanks for letting me know that the code fragment worked. I'll note the suggested change to the queryFactory class.

 

 

Similar Threads

  1. v139h 1136 Column count doesn't match value count at row 1
    By riolas in forum General Questions
    Replies: 3
    Last Post: 5 Jul 2013, 07:48 AM
  2. Replies: 6
    Last Post: 25 Mar 2009, 08:41 PM
  3. After QBI Install - 1136 Column count doesn't match value count at row 1
    By Bostitch in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 2 Apr 2008, 09:24 AM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR