本文实例讲述了PHP查询MysqL数据库并将结果保存到数组的方法。分享给大家供大家参考。具体分析如下:
MysqL_fetch_assoc语法如下:
PHP;">
array MysqL_fetch_assoc (resource $Result_Set)
范例代码如下:
PHP;">
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']
\n"; echo "Title = $Row['Title']
\n"; echo "Author = $Row['Author']
\n"; } ?>
\n"; echo "Title = $Row['Title']
\n"; echo "Author = $Row['Author']
\n"; } ?>
希望本文所述对大家的PHP程序设计有所帮助。
原文链接:https://www.f2er.com/php/22365.html