Press "Enter" to skip to content

[태그:] affected_rows

[PHP] mysql update 된 row 수 체크하기

<?php
$mysql = new mysqli("localhost","username","password","use_db");

if($mysql->connect_errno)
{
  echo "MySQL 접속 실패 : ".$mysql->connect_error;
  exit();
}

// 업데이트 처리
$mysql->query("UPDATE usertable SET name = 'myName' where id = 100");
echo "적용된 row 수: ".$mysql->affected_rows;

$mysqli->close();
?>

SELECT 일때도 동일하게 사용할 수 있습니다.

다만, query() 의 리턴 변수에서 체크하는 것이 아니라 mysqli 인스턴스로 체크합니다.