Chapter 6. Working with Databases

In this chapter, we will cover:

  • Configuring CodeIgniter for databases
  • Connecting to multiple databases
  • Active Record – Create (insert)
  • Active Record – Read (select)
  • Active Record – Update
  • Active Record – Delete
  • Looping through database results
  • Counting the number of returned results with num_rows()
  • Counting the number of returned results with count_all_results()
  • Counting the number of returned results
  • Query binding
  • Finding the last insert ID
  • Finding the number of affected rows
  • Finding the last database query
  • Using CodeIgniter database migrations
  • Moving to the current version with current()
  • Rolling back/stepping forward with version()
  • Generating an XML from a database result
  • Generating a CSV from a database result

Introduction

Pretty much any application you build will require database access and a functionality, from basic Create, Read, Update, and Delete (CRUD) operations to more sophisticated approaches. In this chapter, we'll look at some fairly simple recipes (for example, simple CRUD operations), and then some more capable recipes such as connecting to multiple databases, database caching, and generating files as output.

Some recipes are quite simple, so I won't provide all the files for you to copy (in some cases, it may be unnecessary); instead, many of the recipes are small blocks of code that you can drop into real-world scenarios as you need to.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.182.179