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 815683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:43:23+00:00 2026-05-15T01:43:23+00:00

I am trying to write a PHP-MySQL database processor that is somewhat intelligent. When

  • 0

I am trying to write a PHP-MySQL database processor that is somewhat intelligent. When this processor decides it needs to make an update, I want to report if it was really successful or not. I thought I could use mysql_affected_rows…

// Example:
// After running query "UPDATE mytable SET name='Test' WHERE ID=1"
$result = mysql_affected_rows();
if ($result >= 1) { /* Success */ }

If, for example, there was no row with ID=1, then $result would be 0.

However, it turns out that PHP’s mysql_affected_rows is the actual affected rows, and may be still be 0 if the row exists but name was already “Test”. (The PHP docs even say this is the case).

If I run this in the command line, I get the following meta information about the query:

Query OK, 0 rows affected (0.01 sec)
Rows matched: 1  Changed: 0  Warnings: 0

Is there any way for me to get that “Rows matched” value in PHP instead of the affected rows?

[Edit]: I should note that I know I can run a separate query, but I’d like to not do that, for the sake of performance.

  • 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-05-15T01:43:24+00:00Added an answer on May 15, 2026 at 1:43 am

    From the MySQL documentation for mysql_affected_rows:

    For UPDATE statements, if you specify
    the CLIENT_FOUND_ROWS flag when
    connecting to mysqld,
    mysql_affected_rows() returns the
    number of rows matched by the WHERE
    clause. Otherwise, the default
    behavior is to return the number of
    rows actually changed.

    With mysqli, you can specify the CLIENT_FOUND_ROWS using mysqli::real_connect.

    $db = mysqli_init();
    $db->real_connect('host', 'username', 'password', 'dbname', '3306', null, MYSQLI_CLIENT_FOUND_ROWS);
    

    In PDO, the constant is named PDO::MYSQL_ATTR_FOUND_ROWS

    $db = new PDO('mysql:dbname=mydatabase;host=myhost', 'username', 'password', array(
        PDO::MYSQL_ATTR_FOUND_ROWS => true
    ));
    

    With the old and deprecated MySQL extension, you can specify the CLIENT_FOUND_ROWS passing the value 2 as the 5th parameter for mysql_connect (source).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a PHP script to backup a MySQL database: if (
I'm trying to write a application that sends user's geolocation to MYSQL database every
I'm trying to write a page that calls PHP that's stored in a MySQL
I have a php page that needs to write to a database sometimes at
I am trying to write a php function to stop MySQL injection attempts. What
I am trying to write a PHP script that can upload multiple files. for($i=0;$i<count($_FILES['uploadimg']['name']);$i++){
I am trying to write a PHP script that uses the pdftk app to
I am trying to write a PHP script that listens for incoming $_REQUEST or
I'm trying to write a php function that gets all the basic food data.
I am trying to write a bash or PHP script that will execute a

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.