Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of fetch () and fetch1 () in the secondary development of Imperial CMS

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you the use of fetch () and fetch1 () in the secondary development of Imperial CMS. I hope you will gain a lot after reading this article. Let's discuss it together.

How to use fetch () and fetch2 () in the secondary development of Imperial CMS?

Fetch () and fetch2 () are the functions commonly used in the secondary development of Imperial CMS. The following describes the correct writing and some uses of fetch () and fetch2 ():

(note: the fetch () and fetch2 () functions are located in the e/class/db_sql.php file)

1.fetch ()

In general, we use it to loop out a list or list multiple pieces of information; for example, the following example gets the ID and user names of all members whose membership group ID is 1; the parameter of fetch () is the result of the execution of the SQL statement, that is, query () is executed first; then the execution result of query () is used as a parameter to fetch ()

The code is as follows:

Query ("select userid,username from {$dbtbpre} enewsmember where groupid=1"); while ($r = $empire-> fetch ($sql)) {echo $r [userid]. '- -'. $r [username].';} db_close (); $empire = null

2.fetch2 ()

To put it simply, we only use it when we query a piece of information, such as getting the member information whose USERID is 1; unlike fetch (), the parameter of fetch2 () is the SQL statement rather than the execution result, so it is fine to go in directly if the SQL statement is not used for the second time; fetch2 () takes only one piece of data

The code is as follows

Fetch2 ("select userid,username from {$dbtbpre} enewsmember where userid=1 limit 1"); echo $r [UserID].'; echo $r [username].'; db_close (); $empire=null

Let's discuss it further:

1. Both fetch () and fetch2 () can be used when fetching a message, as follows:

The code is as follows:

Fetch2 ("select id,title from {$dbtbpre} ecms_news where classid=34"); print_r ($R1); echo''; $sql=$empire- > query ("select id,title from {$dbtbpre} ecms_news where classid=34"); $ringing empires-> fetch ($sql); print_r ($r); echo''; db_close (); $empire=null

two。 If you want to use fech2 () to loop data, you can test the following code, and you will find that the result is tragic, endless loop, quickly close the browser

The code is as follows:

Fetch2 ("select id,title from {$dbtbpre} ecms_news where classid=34") {echo $R1 [title];} db_close (); $empire=null

The circular writing of 3.fetch () is also dead.

The code is as follows:

Query ("select id,title from {$dbtbpre} ecms_news where classid=341"); $rented empires-> fetch ($sql); while ($r) {echo $r [title].';} db_close (); $empire=null

4. Why? no, no, no. Trylife once said that there is no code and no truth, so take a look at the contents of the source file: location: e/class/db_sql.php

The code is as follows:

/ / execute mysql_fetch_array () function fetch ($sql) / / the parameter to this method is $sql, which is the result of sql statement execution {$this- > r=mysql_fetch_array ($sql); return $this- > r } / / execute fetch2 (mysql_fetch_array ()) / / the difference between this method and fetch () is: 1, the parameter of this method is $query is the sql statement / / 2, this method is used for while (), the for () database pointer will not automatically move down, while fetch () can automatically move down. Function fetch2 ($query) {$this- > sql=$this- > query ($query); $this- > r=mysql_fetch_array ($this- > sql); return $this- > r;}

1. See that the fetch2 () function has more lines than fetch (): "$this- > sql=$this- > query ($query);"; fetch2 () executes query () first; so when you get a line of information, just fetch2 () and type less code.

two。 The endless loop in the above 3 and 4 is the writing problem of PHP. The while ($ringing query empires-> fetch ($query)) function fetches the first line of the query results first, and then the record pointer automatically moves to the next line; note: mysql_fetch_array only gets the first row of data of the query results first; mysql_fetch_array (), which is not written in while () parentheses, can only read the first row of data all the time, so it loops!

After reading this article, I believe you have a certain understanding of the use of fetch () and fetch1 () in the secondary development of Imperial CMS. If you want to know more about it, welcome to follow the industry information channel. Thank you for your reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report