欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

mysql_assoc_PHP鏁欑▼ | 甯涔嬪

程序员文章站 2022-05-31 17:56:48
...
[php]
function fetch_array($query, $result_type = MYSQL_ASSOC)

{
return mysql_fetch_array($query, $result_type);
}
鍙兘鍦ㄧ湅PHP椤圭洰鐨勬椂鍊欙紝鐗瑰埆鏄拰鏁版嵁搴撹繛鐢ㄧ殑鏃跺€欙紝涓€鑸殑浠g爜閮戒細鍑虹幇杩欐牱鐨勫舰寮忥紝鍙槸鐩稿綋浜庡嚱鏁版帴鍙g殑杞崲銆?/p>

鍏朵腑鏈塎YSQL_ASSOC涓€涓嬪瓙娌$湅鎳傛槸浠€涔堬紝鍚庢潵鏌ヤ簡涓嬫墜鍐岋紝绔熺劧鏄硾娉涚殑璋堜簡涓嬶細

mysql_fetch_array() 涓彲閫夌殑绗簩涓弬鏁?result_type 鏄竴涓父閲忥紝鍙互鎺ュ彈浠ヤ笅鍊硷細MYSQL_ASSOC锛孧YSQL_NUM 鍜?MYSQL_BOTH銆傛湰鐗规€ф槸 PHP 3.0.7 璧锋柊鍔犵殑銆傛湰鍙傛暟鐨勯粯璁ゅ€兼槸 MYSQL_BOTH銆?/p>

杩欒鎴戞湁鐐瑰皬绾犵粨锛屽悗鏉ョ櫨搴︿簡涓嬶紝缁堜簬鐭ラ亾鍖哄埆浜嗐€傚叾涓璏YSQL_ASSOC鏄彧鑳界敤鍏宠仈绱㈠紩锛孧YSQL_NUM鍙兘鐢ㄦ暟瀛楃储寮曪紝MYSQL_BOTH鏁板瓧銆佸叧鑱旈兘鏄彲浠ョ殑銆傦紙ps锛氳繖閲屼笉鐭ラ亾鐢ㄧ储寮曞悎涓嶅悎閫傦紝鍏跺疄涔熷氨鏄暟缁勭殑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); } 鍙兘鍦ㄧ湅PHP椤圭洰鐨勬椂鍊欙紝鐗瑰埆鏄拰鏁版嵁搴撹繛鐢ㄧ殑鏃跺€?..
  • 鍩轰簬PHP鏈嶅姟绔浘鐗囩敓鎴愮缉鐣ュ浘鐨勬柟娉曡瑙PHP鏁欑▼ | 甯涔嬪

  • 瑙f瀽PHP璁$畻椤甸潰鎵ц鏃堕棿鐨勫疄鐜颁唬鐮乢PHP鏁欑▼ | 甯涔嬪

  • include()涓巖equire()鐨勫姣擾PHP鏁欑▼ | 甯涔嬪

  • 璇诲彇ACCESS鏁版嵁鍒癕YSQL鐨凱HP浠g爜 - PHP鍏ラ棬

  • 璇诲彇ACCESS鏁版嵁鍒癕YSQL鐨凱HP浠g爜 - PHP鍏ラ棬

  • PHP cURL鐨勮缁嗕娇鐢ㄦ墜鍐宊PHP鏁欑▼ | 甯涔嬪