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

Operation function arrangement of codeigniter Database

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "the operation function arrangement of codeigniter database". In the operation process of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The copy code is as follows:

/ / query:

$query = $this- > db_query ("SELECT * FROM table")

= =

/ / result () returns an array of objects

$data = $query- > result ()

/ / result_array () returns data

$data = $query- > result_array ()

/ / row () only returns an array of objects

$data = $query- > row ()

/ / num_rows () returns the number of rows of query results

$data = $query- > num_rows ()

/ / num_fields () returns the number of fields requested by the query

$data = $query- > num_fields ()

/ / row_array () returns only a row of arrays

$data = $query- > row_array ()

/ / free_result () frees the memory occupied by the current query and deletes the associated resource identity

$data = $query- > free_result ()

/ *

= =

Insert operation

= =

, /

/ / ID generated by the last insert operation

Echo $this- > db- > insert_id ()

/ / number of rows affected by write and update operations

Echo $this- > db- > affected_rows ()

/ / returns the total number of rows of the specified table

Echo $this- > db- > count_all ('table_name')

/ / output the current database version number

Echo $this- > db- > version ()

/ / output the current database platform

Echo $this- > db- > platform ()

/ / returns the last run query statement

Echo $this- > db- > last_query ()

/ / insert data, the inserted data will be automatically converted and filtered, for example:

/ / $data = array ('name' = > $name,' email' = > $email, 'url' = > $url)

$this- > db- > insert_string ('table_name', $data)

/ *

= =

Update operation

= =

, /

/ / update the data, and the updated data will be automatically converted and filtered, for example:

/ / $data = array ('name' = > $name,' email' = > $email, 'url' = > $url)

/ / $where = "author_id = 1 AND status = 'active'"

$this- > db- > update_string ('table_name', $data, $where)

/ *

= =

Select data

= =

, /

/ / get all the data of the table

$this- > db- > get ('table_name')

/ / the second parameter is the number of output entries, and the third parameter is the start position.

$this- > db- > get ('table_name', 10,20)

/ / get data. The first parameter is the table name, the second is the acquisition condition, and the third is the number of entries.

$this- > db- > get_where ('table_name', array (' id'= > $id), $offset)

/ / obtain data by select

$this- > db- > select ('title, content, date')

$data = $this- > db- > get ('table_name')

/ / get the maximum value of the field. The second parameter is an alias, which is equivalent to max (age) AS nianling

$this- > db- > select_max ('age')

$this- > db- > select_max ('age',' nianling')

/ / get the minimum value of the field

$this- > db- > select_min ('age')

$this- > db- > select_min ('age',' nianling')

/ / get the sum of the field

$this- > db- > select_sum ('age')

$this- > db- > select_sum ('age',' nianling')

/ / Custom from table

$this- > db- > select ('title', content, date')

$this- > db- > from ('table_name')

/ / query condition WHERE name = 'Joe' AND title = "boss" AND status =' active'

$this- > db- > where ('name', $name)

$this- > db- > where ('title', $title)

$this- > db- > where ('status', $status)

/ / scope query

$this- > db- > where_in ('item1',' item2')

$this- > db- > where_not_in ('item1',' item2')

/ / match. The third parameter is the matching pattern title LIKE'% match%'.

$this- > db- > like ('title',' match', 'before/after/both')

This is the end of the content of "the operation function arrangement of codeigniter database". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Development

Wechat

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

12
Report