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.

Slides:



Advertisements
Similar presentations
Day 9. SELECT INSERT UPDATE DELETE » The standard UPDATE statement. UPDATE table SET field1=val1, field2=val2 WHERE condition » Multiple table UPDATE.
Advertisements

PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
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.
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Objectives Connect to MySQL from PHP
1 of 6 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
Intermediate PHP & MySQL
PHP and MySQL Web Development tMyn1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in.
Tutorial 11: Connecting to External Data
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Database Updates Made Easy In WebFocus Using SQL And HTML Painter Sept 2011 Lender Processing Services 1.
INTERNET APPLICATION DEVELOPMENT For More visit:
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Sayed Ahmed Computer Engineering, BUET, Bangladesh MSC, Computer Science, U of Manitoba, Canada
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
MS Access Database Connection. Database? A database is a program that stores data and records in a structured and queryable format. The tools that are.
PHP meets MySQL.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Lec_6 Manipulating MySQL Databases with PHP PHP Programming with MySQL.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
© Anselm Spoerri Web Design Information Visualization Course Prof. Anselm Spoerri
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Creating PHPs to Insert, Update, and Delete Data CS 320.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
Module of the week Webform 7.x-4.0-alpha9 – admin/config/content/webform Add content types, choose allowed fields, default values and advanced options.
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.
Working with Server Side Scripting: PHP Framework (CodeIgniter)
Database Access with SQL
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Introduction to CodeIgniter (CI)
Database application MySQL Database and PhpMyAdmin
Introduction to Web programming
Introduction To Codeigniter
MS Access Database Connection
ISC440: Web Programming 2 Server-side Scripting PHP 3
PL/SQL Programing : Triggers
SELECT & FROM Commands Farrokh Alemi, PhD
Creating and Managing Database Tables
Tutorial 6 PHP & MySQL Li Xu
Introduction to Web programming
Presentation transcript:

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. E.g the file its self represent the example. Kindly refer it. You can have groups of connection e.g $db['default']['hostname'] = 'localhost';// this is one of the default group setting variable there are more to be set. You can change define below another array as: $db[‘GroupName']['hostname'];// second Dimension of you group will be same.

Connecting to your Database There are two ways to connect to a database: Automatically Connecting The "auto connect" feature will load and instantiate the database class with every page load. To enable "auto connecting", add the word database to the library array, as indicated in the following file: application/config/autoload.php Manually Connecting If only some of your pages require database connectivity you can manually connect to your database by adding this line of code in any function where it is needed, or in your class constructor to make the database available globally in that class. $this->load->database(); For Group $this->load->database(‘groupname’);

Quick Example Standard Query With Multiple Results (Object Version) $query = $this->db->query('SELECT name, title, FROM my_table'); foreach ($query->result() as $row) { echo $row->title; echo $row->name; echo $row-> ; } echo 'Total Results: '. $query->num_rows(); Standard Query With Single Result $query = $this->db->query('SELECT name FROM my_table LIMIT 1'); $row = $query->row(); echo $row->name;

Quick Example Standard Query With Multiple Results (Array Version) $query = $this->db->query('SELECT name, title, FROM my_table'); foreach ($query->result_array() as $row) { echo $row['title']; echo $row['name']; echo $row[' ']; } Standard Query With Single Result (Array version) $query = $this->db->query('SELECT name FROM my_table LIMIT 1'); $row = $query->row_array(); echo $row['name'];

Query(); $this->db->query(); To submit a query, use the following function: $this->db->query('YOUR QUERY HERE'); Query Bindings Bindings enable you to simplify your query syntax by letting the system put the queries together for you. Consider the following example: $sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?"; $this->db->query($sql, array(3, 'live', 'Rick')); The question marks in the query are automatically replaced with the values in the array in the second parameter of the query function.

Result Helper Functions $query->num_rows() The number of rows returned by the query. Note: In this example, $query is the variable that the query result object is assigned to: $query = $this->db->query('SELECT * FROM my_table'); echo $query->num_rows(); $query->num_fields() The number of FIELDS (columns) returned by the query. Make sure to call the function using your query result object: $query = $this->db->query('SELECT * FROM my_table'); echo $query->num_fields();

Query Helper Functions $this->db->insert_id() The insert ID number when performing database inserts. $this->db->affected_rows() Displays the number of affected rows, when doing "write" type queries (insert, update, etc.). Note: In MySQL "DELETE FROM TABLE" returns 0 affected rows. The database class has a small hack that allows it to return the correct number of affected rows. By default this hack is enabled but it can be turned off in the database driver file. $this->db->count_all(); Permits you to determine the number of rows in a particular table. Submit the table name in the first parameter. Example: echo $this->db->count_all('my_table'); \ // Produces an integer, like 25

Query Helper Functions $this->db->insert_string(); This function simplifies the process of writing database inserts. Example: $data = array('name' => $name, ' ' => $ , 'url' => $url); $str = $this->db->insert_string('table_name', $data); The first parameter is the table name, The second is an associative array with the data to be inserted. The above example produces: INSERT INTO table_name (name, , url) VALUES ('Rick', 'example.com')

Query Helper Functions $this->db->update_string(); This function simplifies the process of writing database updates. Example: $data = array('name' => $name, ' ' => $ , 'url' => $url); $where = "author_id = 1 AND status = 'active'"; $str = $this->db->update_string('table_name', $data, $where); The first parameter is the table name, the second is an associative array with the data to be updated, and the third parameter is the "where" clause. The above example produces: UPDATE table_name SET name = 'Rick', = url = 'example.com' WHERE author_id = 1 AND status = 'active'