Чтобы получить количество затронутых строк в MySQL, вы можете использовать различные методы в зависимости от языка программирования или интерфейса, который вы используете для взаимодействия с базой данных. Вот несколько распространенных методов:
-
Использование расширения 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; -
Использование расширения 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; -
Использование инструмента командной строки MySQL:
UPDATE table_name SET column_name = 'new_value' WHERE condition; SELECT ROW_COUNT(); -
Использование расширения 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) -
Использование 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) -
Использование 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);