티스토리 뷰
참조 : http://unabated.tistory.com/entry/mysql-%EC%A0%91%EC%86%8D-%EC%97%AC%EB%B6%80-%ED%99%95%EC%9D%B8-%EB%B0%8F-%EC%97%90%EB%9F%AC
<? header("content-type:text/html; charset=utf-8");
//
/*
$db_host_name2 = "IPADDRESS";
//$db_host_name2 = "localhost";
$db_user_name2 = "ID_DATA";
$db_user_passwd2 = "PW_DATA";
$db_name2 = "DB_NAME";
$connect2=mysql_connect( $db_host_name2, $db_user_name2, $db_user_passwd2) or die( "$DB_FAIL");
mysql_select_db($db_name2,$connect2);
mysql_query("SET NAMES UTF8");
extract($_POST);
extract($_GET);
$query = "SELECT * FROM MST_STUDENT WHERE CollegeNumber=`201001001` ";
$result = mysql_query($query,$connect2);
$rowNum2 = mysql_affected_rows();
*/
?>
=====
<?php
//$conn = mysql_connect("localhost", "mysql_user", "mysql_password") or die ("접속 할 수 없습니다.");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
//if (!mysql_select_db("mydbname")) {
if (!mysql_select_db("klc_job")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT id as userid, fullname, userstatus
FROM sometable
WHERE userstatus = 1";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
// While a row of data exists, put that row in $row as an associative array
// Note: If you`re expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you`ll
// then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
echo $row["userid"];
echo $row["fullname"];
echo $row["userstatus"];
}
mysql_free_result($result);
?>
'Language > MySQL' 카테고리의 다른 글
[ MySql ] JOIN 속도를 빠르게! EXPLAIN, STRAIGHT_JOIN (0) | 2017.04.06 |
---|---|
[ MySQL ] SSH 덤프방법 - mysqldump (0) | 2016.08.05 |
[ MySQL ] datatime 날자비교 (0) | 2016.04.05 |
[ MySQL ] TOTAL ROW 검색 속도 - 리스트 페이지 속도가 나오지 않을때 (0) | 2016.03.10 |
[ MySQL ] SHOW WHERE LIKE (0) | 2016.01.25 |