Home > Article > Backend Development > mysql_assoc_PHP氁欑▼ | 宁涔媔
[php]
function fetch_array($query, $result_type = MYSQL_ASSOC)
{
return mysql_fetch_array($query, $result_type);
}
鍙兘鍦ㄧ湅PHP椤圭洰鐨勬椂链欙紝鐗瑰埆鏄拰鏁版嵁搴撹繛鐢ㄧ殑鏃 stomp €欙紵椂欙紝鐗鐗鏄鏄拰鏁版嵁搴撹繛鐢ㄧ殑鏃 stomp €欙紵g摜棑杩欐牱鐨勫舰寮忥紝鍙槸鐩稿綋浜庡嚱鏁版帴鍙g殑杞崲銆?/p>
鍏朵腑链塎YSQL_ASSOC涓€涓嫔瓙娌$湅锛傛槸浠€涔堬紝鍚庢潵鏌ヤ嬶 small
mysql_fetch_array() 涓彲閫夌殑绗簩涓弬鏁?result_type鏄竴涓父阅忥紝鍙栧鎺孧YSQL_NUM 鍜?MYSQL_BOTH 銆傛湰鐗规€ф槸PHP 3.0.7 Bifeng柊鍔犵殑銆傛湰鍙傛暟鐨勯粯璁ゅ€ and槸MYSQL_BOTH銆?/p>
杩杩栜鎴戞湁鐐瑰皬绾犵粨锛屽悗鏉ョ櫨搴〈简涓嬶紝缁堜簬鐭ラ亾涓鍖埏彧鑳界敤鍏宠仈绱㈠紩锛孧YSQL_NUM鍙兘鐢ㄦ暟楃楃储寮曪紝MYSQL_BOTH鏁板瓧銆佸叧鑱旈兘鲮彃繖阅屼笉鐭ラ亾鐢ㄧ储寮曞悎涓嶅悎閫傦紝鍏跺疄涔熷氨鏄暟缁勭殑KEY浜嗭级
EXAMPLE1 MYSQL_NUM
[php]
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf ("ID: %s Name: %s", $row[0], $row[1]);
}
mysql_free_result($result);
?>
[php]
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf ("ID: %s Name: %s", $row["id"], $row["name"]);
}
mysql_free_result($result);
?>
EXAMPLE MYSQL_BOTH
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("ID: %s Name: %s", $row[0], $row["name"]);
}
mysql_free_result($result);
?>
[php]
printf ("ID: %s Name: %s", $row["id"], $row["name"]);
lt;pre name="code" class="php"> printf ("ID: %s Name: %s", $row["id"], $row[1]);
滆€咃小 wolinxuebin