Home  >  Article  >  Backend Development  >  PHP method of using mysql_fetch_object to obtain an object set from query results_PHP tutorial

PHP method of using mysql_fetch_object to obtain an object set from query results_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:02:331192browse

PHP uses mysql_fetch_object to obtain the object set from the query results

This article mainly introduces the PHP method to use mysql_fetch_object to obtain the object set from the query results. The example analyzes PHP The skills of operating mysql_fetch_object to query the database are very practical. Friends in need can refer to it

The example in this article describes how PHP uses mysql_fetch_object to obtain an object set from query results. Share it with everyone for your reference. The specific analysis is as follows:

The mysql_fetch_object function is used to extract result rows from a MySQL result set as an objective array.

mysql_fetch_object syntax:

?

1

array mysql_fetch_object (resource $Result_Set)

1
array mysql_fetch_object (resource $Result_Set)


The Result_Set handle returns a mysql_query query result set.

If the execution is successful, an object containing all data rows will be returned. If it fails, a bool value

will be returned.

Here is the demo code:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

$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_object ($articles)) {

echo "ISBN = $Row->ISBN
n";

echo "Title = $Row->Title
n";

echo "Author = $Row->Author
n";

}

?>

?

1 2

3

5 6 7 8 9
10 11
12 13 14 15 16 17 18 19
<๐ŸŽœ>$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_object ($articles)) {<๐ŸŽœ> <๐ŸŽœ>echo "ISBN = $Row->ISBN
n"; echo "Title = $Row->Title
n"; echo "Author = $Row->Author
n"; } ?>
I hope this article will be helpful to everyoneโ€™s PHP programming design. http://www.bkjia.com/PHPjc/969968.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969968.htmlTechArticlePHP uses mysql_fetch_object to obtain the object set from the query results. This article mainly introduces the method of PHP using mysql_fetch_object to obtain the object set from the query results. The method of obtaining the object set, analyzed with examples...
Statement๏ผš
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn