1 / 16

Relational Dabatases

Relational Dabatases. Three Tier Architecture. RDBMS. R elational D ata b ase M anagement S ystem s A way of saving and accessing data on persistent (disk) storage. Why Use an RDBMS. Relational Model. First published by Edgar F. Codd in 1970 Received Turing Award in 1981

fern
Download Presentation

Relational Dabatases

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Relational Dabatases

  2. Three Tier Architecture

  3. RDBMS • Relational Database Management Systems • A way of saving and accessing data on persistent (disk) storage.

  4. Why Use an RDBMS

  5. Relational Model • First published by Edgar F. Codd in 1970 • Received Turing Award in 1981 • A relational database consists of a collection of tables • A table consists of rows and columns • Each row represents a record • Each column represents an attribute of the records contained in the table

  6. Example

  7. Structured Query Language (SQL) • Queries select c1.name as 'from', c2.name as 'to', t.time, f.date, f.available from flight f, timetable t, campus c1, campus c2 where f.timetable_id = t.id and t.leavingfrom = c1.id and t.goingto = c2.id; • Data manipulation insert into flight (timetable_id, date, available) values (1, current_date(),3) update flight set available = 2 where id = 3 delete from flight

  8. client client Server disk i/o server process Client/Server Databases client processes tcp/ip connections

  9. API tcp/ip connection to server db library Inside the Client Process client application code

  10. CodeIgniter DB API • Implemented by DB.php library • CODEIGNITER_ROOT/core/database • Configuration • CODEIGNITER_ROOT/application/config/database.php $db['default']['hostname'] = ’bungle07.cs.toronto.edu'; $db['default']['username'] = 'c2delara'; $db['default']['password'] = '123456789'; $db['default']['database'] = ’uofttheater'; $db['default']['dbdriver'] = 'mysql’; • Loading • CODEIGNITER_ROOT/application/config/autoload.php $autoload['libraries'] = array('database’); • Controller function $this->load->database();

  11. Running Queries • $query = $this->db->query('YOUR QUERY HERE'); • Return values • Read queries  false if failure, result object if success • Write queries  false if failure, true if success • Error handling • $this->db->_error_message(); • $this->db->_error_number();

  12. Processing Results • $query->num_rows()  num of rows returned by query • $query->result()  array of objects • $query->row(n)  a specific object for the nthtuple • $query->result(Class)  array of objects of type Class • $query->row(n, Class)  a specific object for the nthtuple • $query->result_array()  result as pure array • $query->row_array(n)  an array for the nthtuple • $query->list_fields()  array with field names • $query->field_data()  array with field info (name, max_length, primary_key, type)

  13. Active Data Objects • Pattern that allows information to be retrieved, inserted, and updated with minimal scripting. • Database independent • Query syntax is generated by db adapter • Safer queries • Values automatically escaped

  14. Active Data Objects • Read $query = $this->db->get('mytable');// Produces: SELECT * FROM mytable Modifiers: $this->db->where(), $this->db->like(), $this->db->join(), $this->db->group_by() ,…… • Update $data = array( 'title' => 'My title' , 'name' => 'My Name’ ); $this->db->insert('mytable', $data); // Produces: INSERT INTO mytable (title, name) VALUES ('My title', 'My name’) $this->db->delete('mytable', array('id' => $id)); $this->db->update('mytable', $data, array('id' => $id));

  15. CRUD Pattern • Pattern for operating on db tables • CodeIgniter URL mapping: server_name/app_name/controller_name/create server_name/app_name/controller_name/read/id server_name/app_name/controller_name/update/id server_name/app_name/controller_name/delete/id

  16. Transactions • Atomic changes to multiple db records • Failures • Concurrency control $this->db->trans_begin(); … lots of updates … if ($this->db->trans_status() == FALSE) { $this->db->trans_rollback(); } else { $this->db->trans_commit(); }

More Related