728x90
https://www.php.net/manual/ja/pdostatement.rowcount.php
PDOStatement :: rowCount
public PDOStatement::rowCount ( void ) : int
마지막 SQL 문의 영향을 받는 행 수를 반환합니다.
PDOStatement::rowCount()
returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.
If the last SQL statement executed by the associated PDOStatement was a SELECT statement,
some databases may return the number of rows returned by that statement.
However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.
PDOStatement :: rowCount ()는 해당 PDOStatement 오브젝트에 의해 실행된 마지막 DELETE, INSERT 또는 UPDATE 문의 영향을 받는 행 수를 리턴합니다. 연관된 PDOStatement에 의해 실행된 마지막 SQL 문 이 SELECT 문인 경우 일부 데이터베이스는 해당 명령문에 의해 리턴된 행 수를 리턴할 수 있습니다. 그러나 이 동작이 모든 데이터베이스에 대해 보장되는 것은 아니며 휴대용 응용 프로그램에 의존해서는 안됩니다.
1) INSERT
<?php
$insertStmt = $dbh->prepare("INSERT INTO fruit ('name') VALUE ('apple')");
$insertStmt->execute();
$count = $insertStmt->rowCount();
print("INSERT $count rows.\n");
2) UPDATE
<?php
$updateStmt = $dbh->prepare("UPDATE fruit SET NAME = 'fruit'");
$updateStmt->execute();
$count = $updateStmt->rowCount();
print("UPDATE $count rows.\n");
3) DELETE
<?php
$deleteStmt = $dbh->prepare("DELETE FROM fruit");
$deleteStmt->execute();
$count = $deleteStmt->rowCount();
print("DELETE $count rows.\n");
728x90
'PHP' 카테고리의 다른 글
36. PHP PDO의 bindParam과 bindValue의 차이 (0) | 2021.08.05 |
---|---|
35. PHP 비밀번호 암호화&복호화 password_hash, password_verify (0) | 2021.08.03 |
34. PHP 변수에서 숫자만 추출하기 (0) | 2021.07.23 |
33. PHP 날짜 더하기, 빼기 & 날짜 크기 비교하기 (0) | 2021.07.21 |
32. PHP Form 유효성 검사 & input 데이터 가공 처리 (0) | 2021.07.21 |