1
2<?php
3/* Delete all rows from the FRUIT table */
4$del = $dbh->prepare('DELETE FROM fruit');
5$del->execute();
6
7/* Return number of rows that were deleted */
8print("Return number of rows that were deleted:\n");
9$count = $del->rowCount();
10print("Deleted $count rows.\n");
11?>
12
13
1//Instantiate the PDO object and connect to MySQL.
2$pdo = new PDO(
3 'mysql:host=127.0.0.1;dbname=my_database',
4 'username',
5 'password'
6);
7
8//The COUNT SQL statement that we will use.
9$sql = "SELECT COUNT(*) AS num FROM users";
10
11//Prepare the COUNT SQL statement.
12$stmt = $pdo->prepare($sql);
13
14//Execute the COUNT statement.
15$stmt->execute();
16
17//Fetch the row that MySQL returned.
18$row = $stmt->fetch(PDO::FETCH_ASSOC);
19
20//The $row array will contain "num". Print it out.
21echo $row['num'] . ' users exist.';
22