Home >Backend Development >PHP Tutorial >mysql_assoc_PHP氁欑▼ | 宁涔媔

mysql_assoc_PHP氁欑▼ | 宁涔媔

WBOY
WBOYOriginal
2016-07-13 17:52:061147browse

[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);
?>

EXAMPLE2 MYSQL_ASSOC

[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

[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_BOTH)) {
printf ("ID: %s Name: %s", $row[0], $row["name"]);
}

mysql_free_result($result);
?>

鍏朵腑 MYSQL_BOTH

[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


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478138.htmlTechArticle[php] function fetch_array($query, $result_type = MYSQL_ASSOC) { return mysql_fetch_array($query, $result_type) ; } >
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn