How can the rowCount method in PDO be utilized in PHP for database operations?
The `rowCount` method in PDO can be utilized in PHP for database operations to retrieve the number of rows affected by a SQL statement (such as SELECT, INSERT, UPDATE, DELETE). This can be useful for checking the success of an operation or for displaying the number of affected rows to the user.
// Assuming $pdo is your PDO connection object
$stmt = $pdo->prepare("SELECT * FROM users WHERE status = :status");
$stmt->execute(['status' => 'active']);
$rowCount = $stmt->rowCount();
echo "Number of active users: " . $rowCount;
Keywords
Related Questions
- How can the user modify the code to store the data entered in the JavaScript prompts into PHP variables and then save them in a database?
- In what scenarios would using AES_ENCRYPT() and AES_DECRYPT() be a better option than MD5 encryption for sensitive data in PHP scripts?
- What are some alternative approaches or best practices for handling multiple sessions on a single page in PHP to avoid conflicts or errors?