mysql fetch assoc - ¿¬°ü ¹è¿·Î °á°ú ÇàÀ» ¹Ýȯ |
|
|
 |
14³â Àü |
ÀÎÃâµÈ Çà¿¡¼ ¹®ÀÚ¿ÀÇ ¿¬°ü ¹è¿À» ¹ÝȯÇϰųª ´õ ÀÌ»óÀÇ ÇàÀÌ ¾ø´Ù¸é FALSE¸¦ ¹ÝȯÇÑ´Ù.
<?php
$conn = mysql_connect("localhost", "mysql_user", "mysql_password");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("mydbname")) {
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 ($row = mysql_fetch_assoc($result)) {
echo $row["userid"];
echo $row["fullname"];
echo $row["userstatus"];
}
mysql_free_result($result);
?>
http://docs.php.net/manual/kr/function.mysql-fetch-assoc.php |
|
̵̧ : 317 |
̵̧
¸ñ·Ï
|
|