600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > php查询mysql放到数组中_php查询mysql数据库并将结果保存到数组的方法

php查询mysql放到数组中_php查询mysql数据库并将结果保存到数组的方法

时间:2021-07-02 11:51:12

相关推荐

php查询mysql放到数组中_php查询mysql数据库并将结果保存到数组的方法

本文实例讲述了php查询mysql数据库并将结果保存到数组的方法。。具体分析如下:

这里主要用到了mysql_fetch_assoc函数

mysql_fetch_assoc语法如下:

array mysql_fetch_assoc (resource $Result_Set)

范例代码如下:

$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";

}

?>

希望本文所述对大家的php程序设计有所帮助。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。