Php queries the mysql database and saves the result to an array

Source: Internet
Author: User

Php queries the mysql database and saves the result to an array

This article describes how to query the mysql database in php and save the results to an array. The example shows how to query the database using mysql_fetch_assoc in php. For more information, see

 

 

This example describes how php queries mysql Databases and saves the results to arrays. Share it with you for your reference. The specific analysis is as follows:

The mysql_fetch_assoc function is used here.

The mysql_fetch_assoc syntax is as follows:

?

1

Array mysql_fetch_assoc (resource $ Result_Set)

The sample code is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

<? Php

$ UserName = 'abc ';

$ Password = '000000 ';

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

If (! $ DbHandle ){

Die 'no database connection cocould be established .';

}

$ DBName = 'wdb;

If (! Mysql_select_db ($ DBName, $ DbHandle )){

Die 'database cocould 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 ";

}

?>

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.