php查詢(xún)mysql數(shù)據(jù)庫(kù)并將結(jié)果保存到數(shù)組的方法
來(lái)源:易賢網(wǎng) 閱讀:4104 次 日期:2015-03-19 14:06:37
溫馨提示:易賢網(wǎng)小編為您整理了“php查詢(xún)mysql數(shù)據(jù)庫(kù)并將結(jié)果保存到數(shù)組的方法”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了php查詢(xún)mysql數(shù)據(jù)庫(kù)并將結(jié)果保存到數(shù)組的方法,實(shí)例分析了php使用mysql_fetch_assoc查詢(xún)數(shù)據(jù)庫(kù)的技巧,需要的朋友可以參考下

本文實(shí)例講述了php查詢(xún)mysql數(shù)據(jù)庫(kù)并將結(jié)果保存到數(shù)組的方法。分享給大家供大家參考。具體分析如下:

這里主要用到了mysql_fetch_assoc函數(shù)

mysql_fetch_assoc語(yǔ)法如下:

array mysql_fetch_assoc (resource $Result_Set)

范例代碼如下:

<?php

$UserName = 'abc';

$Password = '1234';

$DbHandle = mysql_connect ('localhost', $UserName, $Password);

if (!$DbHandle) {

die 'No database connection could be established.';

}

$DBName = 'w3db;

if (!mysql_select_db ($DBName, $DbHandle)) {

die 'Database could not be selected.';

}

$Query = "SELECT ISBN, Title, Author FROM articles";

$articles = mysql_query ($Query, $DbHandle));

while ($Row = mysql_fetch_assoc ($articles)) {

echo "ISBN = $Row['ISBN']<br />\n";

echo "Title = $Row['Title']<br />\n";

echo "Author = $Row['Author']<br />\n";

}

?>

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn)

版權(quán)所有:易賢網(wǎng)