본문으로 바로가기

PDO insert, update, delete 한 행 수 확인하기

category PHP 2020. 2. 18. 18:15
반응형

 


PDOStatement :: rowCount
public PDOStatement::rowCount ( void ) : int

Returns the number of rows affected by the last SQL statement
마지막 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");

 

#1) UPDATE

<?php
$updateStmt = $dbh->prepare("UPDATE fruit SET NAME = 'fruit'");
$updateStmt->execute();

$count = $updateStmt->rowCount();
print("UPDATE $count rows.\n");

 

#1) DELETE

<?php
$deleteStmt = $dbh->prepare("DELETE FROM fruit");
$deleteStmt->execute();

$count = $deleteStmt->rowCount();
print("DELETE $count rows.\n");
반응형

'PHP' 카테고리의 다른 글

PHP 자주 사용하는 SERVER 변수  (0) 2020.02.17
PHP 비동기 처리  (2) 2020.02.12
PHP CURL 사용법  (0) 2020.02.06
PHP 값이 배열 안에 존재하는지 확인하는 in_array 함수  (0) 2020.01.31
PHP 문자열 함수  (0) 2019.12.04