<?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 인스턴스로 체크합니다.
One Comment
// 조회시
$sql = “SELECT * FROM table”;
$res = mysql_query($sql, $conn_db);
$tot_rows = mysql_num_rows($res);
// 업데이트, 인서트, 딜리트 시
$usql = “update set status = ‘N’ table where id = 10”;
$ures = mysql_query($usql, $conn_db);
$totcnt = mysql_affected_rows($conn_db);