affected_rows.php

PHOTO EMBED

Thu Sep 08 2022 09:17:16 GMT+0000 (Coordinated Universal Time)

Saved by @vmap #php #mysql #pdo

<?php
//The code example deletes three rows. It prints the number of affected rows.


$dsn = "mysql:host=localhost;dbname=mydb";
$user = "user12";
$passwd = "12user";

$pdo = new PDO($dsn, $user, $passwd);

$id = 12;

//In this SQL statement, we delete rows with ids 1, 2, and 3. The number of deleted rows is stored in the $nrows variable.
$nrows = $pdo->exec("DELETE FROM countries WHERE id IN (1, 2, 3)");

//We print the number of deleted rows.
echo "The statement affected $nrows rows\n";

?>
content_copyCOPY

https://zetcode.com/php/pdo/