Introduction To Codeigniter

Slides:



Advertisements
Similar presentations
PHP and MySQL Database. Connecting to MySQL Note: you need to make sure that you have MySQL software properly installed on your computer before you attempt.
Advertisements

1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Introduction to Structured Query Language (SQL)
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
Introduction to SQL Structured Query Language Martin Egerhill.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 9 Joining Data from Multiple Tables
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Single-Table Queries 1: Basics CS 320 Online. Review: SQL Command Types  Data Definition Language (DDL)  Used to create and modify database objects.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Information Building and Retrieval Using MySQL Track 3 : Basic Course in Database.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Working With Database Library And Helpers. Connecting to your Database First you need to set parameters in you database.php file residing in config folder.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
 CONACT UC:  Magnific training   
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
Working with Server Side Scripting: PHP Framework (CodeIgniter)
Cosc 5/4730 Sqlite primer.
Microsoft Office Access 2010 Lab 3
Chapter 5 Introduction to SQL.
Relational Model.
Relational Database Design
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
ATS Application Programming: Java Programming
Database Systems: Design, Implementation, and Management Tenth Edition
Introduction to CodeIgniter (CI)
Introduction to Web programming
JDBC.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Structured Query Language (SQL) William Klingelsmith
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
Developing a Model-View-Controller Component for Joomla Part 3
MongoDB Read/Write.
Introduction To Structured Query Language (SQL)
Updating Databases With Open SQL
Introduction to Web programming
Shelly Cashman: Microsoft Access 2016
Updating Databases With Open SQL
Presentation transcript:

Introduction To Codeigniter

Active Record Class CodeIgniter uses a modified version of the Active Record Database Pattern. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a database action.

Active Record Class $this->db->get_where(); Selecting Data Runs the selection query and returns the result. Can be used by itself to retrieve all records from a table: The second and third parameters enable you to set a limit and offset clause: Example: $query = $this->db->get('mytable', 10, 20); // Produces: SELECT * FROM mytable LIMIT 20, 10 (in MySQL). $this->db->get_where(); Identical to the above function except that it permits you to add a "where" clause in the second parameter, instead of using the db->where() function: $query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset);

Active Record Class Selecting Data: $this->db->select(); Permits you to write the SELECT portion of your query: $this->db->select('title, content, date'); $query = $this->db->get('mytable'); // Produces: SELECT title, content, date FROM mytable. $this->db->from(); Permits you to write the FROM portion of your query: $this->db->select('title, content, date'); $this->db->from('mytable'); $query = $this->db->get(); // Produces: SELECT title, content, date FROM mytable

Active Record Class Selecting Data: $this->db->join(); Permits you to write the JOIN portion of your query: $this->db->select('*'); $this->db->from('blogs'); $this->db->join('comments', 'comments.id = blogs.id'); $query = $this->db->get(); // Produces:  // SELECT * FROM blogs // JOIN comments ON comments.id = blogs.id Multiple function calls can be made if you need several joins in one query. A specific type of JOIN can be specified via the third parameter of the function. Options are: left, right, outer, inner, left outer, and right outer. $this->db->join('comments', 'comments.id = blogs.id', 'left'); // Produces: LEFT JOIN comments ON comments.id = blogs.id

Active Record Class Selecting Data: $this->db->where(); This function enables you to set WHERE clauses using one of four methods: $this->db->where('name', $name);  // Produces: WHERE name = 'Joe‘ If you use multiple function calls they will be chained together with AND between them: $this->db->where('name', $name); $this->db->where('title', $title); $this->db->where('status', $status);  // WHERE name = 'Joe' AND title = 'boss' AND status = 'active'

Active Record Class Selecting Data: $this->db->where(); This function enables you to set WHERE clauses using one of four methods: Simple key/value method: $this->db->where('name', $name);  // Produces: WHERE name = 'Joe‘ If you use multiple function calls they will be chained together with AND between them: $this->db->where('name', $name); $this->db->where('title', $title); // WHERE name = 'Joe' AND title = 'boss' Custom key/value method: You can include an operator in the first parameter in order to control the comparison: $this->db->where('name !=', $name); $this->db->where('id <', $id);  // Produces: WHERE name != 'Joe' AND id < 45

Active Record Class Custom string: Selecting Data: $this->db->where(); This function enables you to set WHERE clauses using one of four methods: Associative array method: $array = array('name' => $name, 'title' => $title, 'status' => $status); $this->db->where($array);  // Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active‘ You can include your own operators using this method as well: $array = array('name !=' => $name, 'id <' => $id, 'date >' => $date); $this->db->where($array); Custom string: You can write your own clauses manually: $where = "name='Joe' AND status='boss' OR status='active'"; $this->db->where($where);

Active Record Class $this->db->having(); Selecting Data: $this->db->group_by(); $this->db->group_by("title");  $this->db->like(); This function enables you to generate LIKE clauses, useful for doing searches. $this->db->like('title', 'match');  // Produces: WHERE title LIKE '%match%‘ If you want to control where the wildcard (%) is placed, you can use an optional third argument. Your options are 'before', 'after' and 'both' (which is the default). $this->db->having(); $this->db->having('user_id = 45');  // Produces: HAVING user_id = 45 $this->db->having('user_id', 45);  // Produces: HAVING user_id = 45 $this->db->order_by(); Lets you set an ORDER BY clause. The first parameter contains the name of the column you would like to order by. The second parameter lets you set the direction of the result. Options are asc or desc, or random. $this->db->order_by("title", "desc"); 

Insert $this->db->insert(); Generates an insert string based on the data you supply, and runs the query. You can either pass an array or an object to the function. Here is an example using an array: $data = array(    'title' => 'My title' ,    'name' => 'My Name' ,    'date' => 'My date' ); $this->db->insert('mytable', $data);  // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')

Batch Insert $this->db->insert_batch(); Generates an insert string based on the data you supply, and runs the query. You can either pass an array or an object to the function. Here is an example using an array: $data = array(    array(       'title' => 'My title' ,       'name' => 'My Name' ,       'date' => 'My date'    ),    array(       'title' => 'Another title' ,       'name' => 'Another Name' ,       'date' => 'Another date'    ) ); $this->db->insert_batch('mytable', $data);  // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')

Update $this->db->update(); Generates an update string and runs the query based on the data you supply. You can pass an array or an object to the function. Here is an example using an array: $data = array(                'title' => $title,                'name' => $name,                'date' => $date             ); $this->db->where('id', $id); $this->db->update('mytable', $data);  // Produces: // UPDATE mytable  // SET title = '{$title}', name = '{$name}', date = '{$date}' // WHERE id = $id. .

Batch Update $this->db->update_batch(); Generates an update string based on the data you supply, and runs the query. You can either pass an array or an object to the function. Here is an example using an array: $data = array(    array(       'title' => 'My title' ,       'name' => 'My Name 2' ,       'date' => 'My date 2'    ),    array(       'title' => 'Another title' ,       'name' => 'Another Name 2' ,       'date' => 'Another date 2'    ) ); $this->db->update_batch('mytable', $data, 'title');  // Produces:  // UPDATE `mytable` SET `name` = CASE // WHEN `title` = 'My title' THEN 'My Name 2' // WHEN `title` = 'Another title' THEN 'Another Name 2' // ELSE `name` END, // `date` = CASE  // WHEN `title` = 'My title' THEN 'My date 2' // WHEN `title` = 'Another title' THEN 'Another date 2' // ELSE `date` END // WHERE `title` IN ('My title','Another title')

Delete $this->db->delete(); Generates a delete SQL string and runs the query. $this->db->delete('mytable', array('id' => $id));  OR $this->db->where('id', $id); $this->db->delete('mytable');  // Produces: // DELETE FROM mytable  // WHERE id = $id 

Method Chaining Method chaining allows you to simplify your syntax by connecting multiple functions. Consider this example: $this->db->select('title')->from('mytable')->where('id', $id)->limit(10, 20); $query = $this->db->get();