Database 20/2/12 Connection. 

Slides:



Advertisements
Similar presentations
Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
Advertisements

Connecting to Database 21 Feb Database Options Can use many different databases in conjunction with php. – MySql; MS Access; Oracle; etc etc Most.
CIS 375—Web App Dev II ADO I. 2 Introduction ADO (________ Data Objects) is a Microsoft technology for accessing data in a database. ADO is automatically.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
ASP Application Development Session 3. Topics Covered Using SQL Statements for: –Inserting a tuple –Deleting a tuple –Updating a tuple Using the RecordSet.
Java, Access, SQL, HTML. Three-tier architecture involves: Client - Browser Server - Tomcat Database - Access - Server-side language - JSP could just.
The ADO Data Control. Universal Data Access Open Database Connectivity (ODBC) –standard for accessing data in databases OLE-DB –allows access to data.
ActiveX Data Object ISYS 562. ADO An ActiveX control ActiveX is build upon COM, a contract that defines a standard interface by which objects communicate.
Fundamentals, Design, and Implementation, 9/e COS 346 DAY 22.
Objectives Connect to MySQL from PHP
Multiple Tiers in Action
CSE 190: Internet E-Commerce Lecture 13: Database code.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
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.
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
How to using MS Access database in Perl/CGI Web Programming Wei Sun.
ODBC Open DataBase Connectivity a standard database access method developed by Microsoft to access data from any application regardless of which database.
+ Connecting to the Web Week 7, Lecture A. + Midterm Basics Thursday February 28 during Class The lab Tuesday, February 26 is optional review Class on.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Interacting With Data Week 8 Connecting to the database Creating recordsets Interacting with the database.
Interacting With Data Databases.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
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))
ActiveX Data Object (ADO) in JavaScript J.L.Wang, Yen-Cheng Chen Dept. of Infomation Management Ming-Chuan University Jan
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10.
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.
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.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Lecture Note 10: Simple Database Techniques. Introduction –Database System –Access, SQL Server and others. –Microsoft Access - Interacting with this databases.
What is database?  Any Method for access info into Application from DataBase?  ODBC is standard for Accessing Data.  Problem with ODBC:  Information.
Creating PHPs to Insert, Update, and Delete Data CS 320.
How to Connect to Database ODBC (Open Database Connectivity) ADO (ActiveX Data Object) ASP Code To Connect to Database Recordset Object Navigating through.
ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard set of objects to refer.
Chapter 9 Building the Shopping cart Objective Creating Shopping cart using session Variable. Creating a shopping cart using a database table. Use the.
Mauricio Featherman, Ph.D. Washington St. University
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
AVCE ICT – Unit 7 - Programming Session 16 – Database and VB.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Lab 8 Data Access Using Microsoft ActiveX Data Object (ADO)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.
Database Connectivity and Server-Side Scripting Chapter 12.
What’s new in ADO 2.5 Greg Hinkel Program Manager Data Access Group
What’s new in ADO 2.5 Greg Hinkel Program Manager Data Access Group
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 6: Accessing a database with PHP Rob Gleasure robgleasure.com.
Labtest.ASP Notes. INSERT STATUS INSERT STATUS
Using databases ActiveX Data Objects (ADO) Connecting to a database Reading data from a database Inserting, updating and deleting records Using databases.
Chapter 5 Building Your Product Catalog database Objectives Create Database. Create Table. Connect to Database. Use ASP Script to add new products. Use.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Dynamic Web Programming
ActiveX Data Objects (ADO)
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 6 Displaying Your Products
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Chapter 10 ASP and Data Store Access
Tutorial 6 PHP & MySQL Li Xu
Database Connections.
Presentation transcript:

Database 20/2/12 Connection

3 Client PC Request Data stored on DB Db Web Server – Corvus 3 Data retrieved from Db and sent to browser window

 This ability to access multiple types of data stores with a relative simple and flat object model, make ADO the simplest method yet devised for retrieving data ◦ ADO works with ODBC compliant sources 4

 The Connection Object is used to hold information about the data store you want to access  Because it is an Object it has properties and methods  Some of these will be needed when creating you PHP application 5

 Before you can retrieve any data from a database, you have to create and initalise a connection to that database  ADODB contains all the ADO objects that you will need to use  In order to use any of the Object from the ADO Object Model you will need to create them  PHP uses the following syntax for creating an Instance of an object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); Note: we store the connection in a variable ($conn) for later use in the script. The "die" part will be executed if the connection fails. 6

 Connection String ‘tells’ your connection what database you wish to connect to.  If you have a system DSN set up all you need do is supply this when setting the connection String.  This is the simplest form of string that can be used.  The connection can also be used for a DSN-less connection. 7

$connStr = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Inetpub\wwwroot\MBSEBus\CHeav in\Databases\cus.accdb"; Note: WWWRoot is a hidden folder (by default) and can't be displayed in directory listing 8

 Connection strings are string variables which contain database connection information and then passed to ADO(ActiveX Data Objects) which will interpret them and act accordingly  They need to be in a comprehensible for ADO format  If you're connecting to an MS Access database, you need the DRIVER, and the DBQ, and some other optional information 9

 When the you have created an instance of the connection object and you have created the assigned a connection string you then need to explicitly open the connection to the database.  To open a connection: $conn->open($connStr);  If the Open method executes you have a working connection to the database 10

 As with any Object you need to free the memory associated with it when you are finished.  However, before you do that, you need to close the connection $conn->Close(); 11

 If you wanted to close the connection but connect to a different data source, you can use the same instance of the connection object.  Simply close the connection first, the set the connection information appropriately and, and reopen it. 12

 Setting up the recordset $rS = $conn->execute("SELECT * FROM test"); 13

After connecting to a database. You may want to do all or some of the following: ◦ Read Data ◦ Write Data ◦ Delete Data 14

◦ Recordset is simply a set of records. ◦ The Recordset may be used to contain  a subset of all the records in a table  All the records in a table.  A specifically chosen set of records  Using a specific SQL statement.  You will need to create an instance of the recordset object before you can use it 15

$rS = $conn->execute("SELECT * FROM test"); $f1 = $rS->Fields(0); $f2 = $rS->Fields(1); while (!$rS->EOF) { print $f1->value." ".$f2->value." \n"; $rS->MoveNext(); } $rS->Close(); 16

Untitled 1 <?php //create an instance of the ADO connection object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); //define connection string, specify database driver $connStr = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Inetpub\wwwroot\MBSEBus\CHeavin\Databases\cus.accdb"; //Open the connection to the database $conn->open($connStr); echo "Connection Open "; //recordset code $rS = $conn->execute("SELECT * FROM test"); $f1 = $rS->Fields(0); $f2 = $rS->Fields(1); while (!$rS->EOF) { print $f1->value." ".$f2->value." \n"; $rS->MoveNext(); } $rS->Close(); $conn->Close(); ?> 17 Select Records

18

Example: $sql="UPDATE test SET name='Mary' WHERE name='Ciaran'"; 19

Untitled 1 <?php //create an instance of the ADO connection object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); //define connection string, specify database driver $connStr = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Inetpub\wwwroot\mbsebus\CHeavin\Databases\cus.accdb"; //Open the connection to the database $conn->open($connStr); echo "Connection Open "; $sql="UPDATE test SET name='Ciara' WHERE name='harry'"; $rS = $conn->execute($sql); echo "Record Updated "; $conn->Close(); ?> 20

$sql="DELETE * FROM test WHERE name='barry'"; 21

Untitled 1 <?php //create an instance of the ADO connection object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); //define connection string, specify database driver $connStr = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Inetpub\wwwroot\mbsebus\CHeavin\Databases\cus.accdb"; //Open the connection to the database $conn->open($connStr); $sql="DELETE * FROM test WHERE name='Ciara'"; echo "Connection Open "; $rS = $conn->execute($sql); print "Record Deleted"; $conn->Close(); ?> 22

$sql="INSERT INTO test (name,age) VALUES ('".$name1."','".$age1."' );"; //Set SQL query 23

Untitled 1 <?php //create an instance of the ADO connection object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); //define connection string, specify database driver $connStr="PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Inetpub\wwwroot\mbsebus\CHeavin\Databases\cus.accdb"; //Open the connection to the database $conn->open($connStr); echo "Connection Open "; $name1="barack obama"; $age1="32"; $sql="INSERT INTO test (name,age) VALUES ('".$name1."','".$age1."' );"; //Set SQL query $conn->Execute($sql); //Execute SQL query print "Record Inserted"; $conn->Close(); //Close database connection ?> 24

Join Name: Age: 25

Untitled 1 New User Name: Age: <?php //create an instance of the ADO connection object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); //define connection string, specify database driver $connStr="PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Inetpub\wwwroot\mbsebus\CHeavin\Databases\cus.accdb"; //Open the connection to the database $conn->open($connStr); $name=$_POST['cust_name']; $age=$_POST['cust_age']; $sql="INSERT INTO test (name,age) VALUES ('".$name."','".$age."' );"; //Set SQL query $conn->Execute($sql); //Execute SQL query $conn->Close(); //Close database connection ?> 26