Получить количество затронутых строк в MySQL

Чтобы получить количество затронутых строк в MySQL, вы можете использовать различные методы в зависимости от языка программирования или интерфейса, который вы используете для взаимодействия с базой данных. Вот несколько распространенных методов:

  1. Использование расширения PHP MySQLi:

    // Execute the query
    $result = $mysqli->query("UPDATE table_name SET column_name = 'new_value' WHERE condition");
    // Get the number of affected rows
    $affected_rows = $mysqli->affected_rows;
    // Print the result
    echo "Affected rows: " . $affected_rows;
  2. Использование расширения PHP PDO:

    // Prepare and execute the query
    $stmt = $pdo->prepare("UPDATE table_name SET column_name = 'new_value' WHERE condition");
    $stmt->execute();
    // Get the number of affected rows
    $affected_rows = $stmt->rowCount();
    // Print the result
    echo "Affected rows: " . $affected_rows;
  3. Использование инструмента командной строки MySQL:

    UPDATE table_name SET column_name = 'new_value' WHERE condition;
    SELECT ROW_COUNT();
  4. Использование расширения MySQLi в Python:

    # Execute the query
    cursor.execute("UPDATE table_name SET column_name = 'new_value' WHERE condition")
    # Get the number of affected rows
    affected_rows = cursor.rowcount
    # Print the result
    print("Affected rows:", affected_rows)
  5. Использование MySQL Connector/Python:

    # Execute the query
    cursor.execute("UPDATE table_name SET column_name = 'new_value' WHERE condition")
    # Get the number of affected rows
    affected_rows = cursor.rowcount
    # Print the result
    print("Affected rows:", affected_rows)
  6. Использование MySQL Connector/J для Java:

    // Execute the query
    Statement statement = connection.createStatement();
    int affectedRows = statement.executeUpdate("UPDATE table_name SET column_name = 'new_value' WHERE condition");
    // Print the result
    System.out.println("Affected rows: " + affectedRows);