Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8093413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:29:55+00:00 2026-06-05T20:29:55+00:00

I have a mysql ON DUPLICATE KEY UPDATE statement that is running successfuly. Although

  • 0

I have a mysql ON DUPLICATE KEY UPDATE statement that is running successfuly.

Although in the manual it says that for a row inserted the affected rows is 1 and an updated row is 2. I figured I could work out the number of inserted rows by simply doing;

$i = count($insert); // the insert array
// execute the query here
$inserted = ($i * 2) - $q -> rowCount();

The equation that equals $inserted returns the number of inserted rows (according to mysql).

Though on my laptop running wamp, when inserting with only duplicate values I get a row count of 0! Why could this be?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:29:56+00:00Added an answer on June 5, 2026 at 8:29 pm

    The rowCount() function will only return 1 or 2, denoting an update or an insert. Using the ON DUPLICATE KEY UPDATE means you forgo the knowing how many rows were affected if you do multiple insert/updates.

    In your instance, it could be that you are getting a row count of 0 because if you do update with identical values the return value is 0 (i.e. no change). A comment on the PHP manual suggests you can add the PDO attribute PDO::MYSQL_ATTR_FOUND_ROWS to true to get how many rows your update-query actually found/matched.

    E.g.

    $p = new PDO($dsn, $u, $p, array(PDO::MYSQL_ATTR_FOUND_ROWS => true));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mySQL query using ON DUPLICATE KEY UPDATE that I am runnining
In MySQL, if you specify ON DUPLICATE KEY UPDATE and a row is inserted
I have an INSERT INTO ... ON DUPLICATE KEY UPDATE ... statement that executes
I read about the MySQL command ON DUPLICATE KEY UPDATE . I have a
I have MySQL running such that I can open a client command line and
I have a MySQL database table that contains an Article ID ( primary key
I have a MySQL insert statement that inserts data from an existing Despgoods table
What would cause ON DUPLICATE KEY UPDATE statement to increase value by 2 instead
I have a MySQL query that looks like this: UPDATE `Table` SET `Column` =
What will mysql do with both INSERT IGNORE and … ON DUPLICATE KEY UPDATE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.