"Query int"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 16개는 보이지 않습니다)
1번째 줄: 1번째 줄:
{{소문자}}
*쿼리 결과를 int로 가져오기.
*쿼리 결과를 int로 가져오기.
*주로 COUNT를 위해 사용.  
*주로 COUNT를 위해 사용.  


<source lang='php'>
==PHP with MySQL==
function intQuery($qry) {
<syntaxhighlight lang='php'>
function query_int($qry) {
$result = mysql_query($qry);
$result = mysql_query($qry);
if($result === false)
die("query_error [ $qry ] message : ".mysql_error());
$row = mysql_fetch_array($result, MYSQL_NUM);
$row = mysql_fetch_array($result, MYSQL_NUM);
return $row[0];
return $row[0];
}
}


$cnt1 = intQuery("SELECT COUNT(*) FROM table1");
// 사용 예시
$cnt2 = intQuery("SELECT COUNT(*) FROM table2 WHERE no='1'");
$cnt1 = query_int("SELECT COUNT(*) FROM table1");
$cnt2 = query_int("SELECT COUNT(*) FROM table2 WHERE idx='1'");
$emp_no = query_int("SELECT emp_no FROM employee WHERE name='홍길동'");


</source>
</syntaxhighlight>
 
==같이 보기==
*[[query_one]]


[[분류:DB]]
[[분류:DB]]
[[분류:php]]
[[분류:PHP]]
[[분류:함수2]]
[[분류:커스텀 함수]]

2020년 11월 2일 (월) 02:35 기준 최신판

  • 쿼리 결과를 int로 가져오기.
  • 주로 COUNT를 위해 사용.

1 PHP with MySQL[ | ]

function query_int($qry) {
	$result = mysql_query($qry);
	if($result === false)
		die("query_error [ $qry ] message : ".mysql_error());
	$row = mysql_fetch_array($result, MYSQL_NUM);
	return $row[0];
}

// 사용 예시
$cnt1 = query_int("SELECT COUNT(*) FROM table1");
$cnt2 = query_int("SELECT COUNT(*) FROM table2 WHERE idx='1'");
$emp_no = query_int("SELECT emp_no FROM employee WHERE name='홍길동'");

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}