SlideShare a Scribd company logo
How to connect to MS Access. PHP
and ODBC
// Microsoft Access
• $connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=FileN
ame“[, $user, $password]);
EX: INSERT DATA
<?php
$db = realpath("./db1.mdb");
$conn = new COM('ADODB.Connection');
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
$insert = "insert into tbProduct(ProductID, ProName, Quantity, UnitPrice) values(1, 'cc', 2,4)";
$res = $conn->Execute($insert);?>
EX: DELETE
<?php
$db = realpath("./db1.mdb");
$conn = new COM('ADODB.Connection');
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
$delete = "DELETE FROM tbProduct WHERE ProductID=4";
$res = $conn->Execute($delete);
?>
EX: UPDATE
<?php
$db = realpath("./db1.mdb");
$conn = new COM('ADODB.Connection');
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
$update = "UPDATE tbProduct SET ProName='dddd', Quantity=34, UnitPrice=5 WHERE
ProductID=1";
$res = $conn->Execute($update);
?>
EX:
<?php
$db_conn = new COM("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./db1.mdb").";";
$db_conn->open($connstr);
$rS = $db_conn->execute("SELECT * FROM tbProduct");
$f1 = $rS->Fields(0);
$f2 = $rS->Fields(1); //$rs->Fields['ProName']->Value
$f3= $rS->Fields(2);
$f4= $rS->Fields(3);
$st="<table
border=1><tr><th>ProID</th><th>ProName</th><th>Quantity</th><th>UnitPrice</th><th>Tot
al</th></tr>";
while (!$rS->EOF) {
$st.="<tr><td>" . $f1->value . "</td><td>" . $f2->value . "</td><td>" . $f3->value .
"</td><td>" . $f4->value . "$</td><td>" . ($f4->value)*($f3->value) . "$</td></tr>";
$rS->MoveNext();
}
$st.="</table>";
print $st;
$rS->Close();
$db_conn->Close();
?>
• It is easy if you run Web Server on Widows PC.
• Windows 2000, XP, Vista ODBC located inside Administrative Tools folder. Double
click ODBC Data Sources. ODBC Data Source Administrator window displays.
EX:
<?php
$conn=odbc_connect("dbProduct","" ,"");
print('<body>');
print('<table align="center" width="90%" border=1>');
print('<tr><th>ProductID</th><th>ProductName</th><th>Quantity</th><th>UnitPrice</th><th
>Total</th></tr>');
if($conn)
{
$sql="select * from tbProduct";
$row=odbc_exec($conn, $sql);
while(odbc_fetch_row($row)){
$proID=odbc_result($row,1);
$proName=odbc_result($row,2);
$quantity=odbc_result($row,3);
$unitPrice=odbc_result($row,4);
print('<tr><td>'.$proID.'</td><td>'. $proName.'</td><td>'.$quantity.'</td><td>' . $unitPrice .
'$</td><td>' . $unitPrice*$quantity . '$</td></tr>');}}
print('</table>');
print('</body>');
print('</html>');
?>
Ch5(ms access with php)

More Related Content

PPTX
PHP Lecture 4 - Working with form, GET and Post Methods
PPTX
PHP Lecture 6 - Php file uploading
PDF
Diving into php
ODP
The promise of asynchronous PHP
PPTX
Aggregation in MongoDB
PDF
React PHP: the NodeJS challenger
PDF
Asynchronous I/O in PHP
PPTX
Everyday's JS
PHP Lecture 4 - Working with form, GET and Post Methods
PHP Lecture 6 - Php file uploading
Diving into php
The promise of asynchronous PHP
Aggregation in MongoDB
React PHP: the NodeJS challenger
Asynchronous I/O in PHP
Everyday's JS

What's hot (20)

PDF
Aggregation Framework MongoDB Days Munich
PPTX
Jquery optimization-tips
ODP
Aggregation Framework in MongoDB Overview Part-1
PDF
PHP Web Development
PDF
Couchdb
KEY
Zf Zend Db by aida
PDF
HOW TO UPLOAD AND DISPLAY IMAGE PHP HTML SQL
KEY
Week 4 - jQuery + Ajax
PDF
The Beauty of Java Script
PDF
jQuery in 15 minutes
PDF
History of jQuery
PDF
Remy Sharp The DOM scripting toolkit jQuery
PDF
Drupal.Behaviors
PDF
Javascript jQuery jQuery Ui
PDF
Dependency Injection
PDF
The Beauty Of Java Script V5a
PDF
Joe Walker Interactivewebsites Cometand Dwr
PDF
Cycle.js: Functional and Reactive
PPT
Aggregation Framework MongoDB Days Munich
Jquery optimization-tips
Aggregation Framework in MongoDB Overview Part-1
PHP Web Development
Couchdb
Zf Zend Db by aida
HOW TO UPLOAD AND DISPLAY IMAGE PHP HTML SQL
Week 4 - jQuery + Ajax
The Beauty of Java Script
jQuery in 15 minutes
History of jQuery
Remy Sharp The DOM scripting toolkit jQuery
Drupal.Behaviors
Javascript jQuery jQuery Ui
Dependency Injection
The Beauty Of Java Script V5a
Joe Walker Interactivewebsites Cometand Dwr
Cycle.js: Functional and Reactive
Ad

Viewers also liked (20)

PPTX
Survey Grade LiDAR Technologies for Transportation Engineering
PPT
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
PPTX
Ch2(working with forms)
PDF
Drought: Looking Back and Planning Ahead, Todd Votteler
PPTX
Voice
PDF
Appendex f
PPT
Final morris esri_nwgis_lidar
PDF
Appendex e
PDF
300 Years of Groundwater Management, Charles Porter
PDF
Ch07
PDF
Appendex b
PPT
PHP 5.3 Part 1 - Introduction to PHP 5.3
PDF
Guidelines for Modelling Groundwater Surface Water Interaction in eWater Source
PPT
Chapter 1Into the Internet
PPTX
Ch4(saving state with cookies and query strings)
PDF
Aquifer Storage and Recovery, Kelley Neumann
PPT
Introduction to PHP
PPTX
eMail 101 (4) Class for Self help Virtual Senior Center
PDF
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
PPT
Chapter 10 Synchronous Communication
Survey Grade LiDAR Technologies for Transportation Engineering
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Ch2(working with forms)
Drought: Looking Back and Planning Ahead, Todd Votteler
Voice
Appendex f
Final morris esri_nwgis_lidar
Appendex e
300 Years of Groundwater Management, Charles Porter
Ch07
Appendex b
PHP 5.3 Part 1 - Introduction to PHP 5.3
Guidelines for Modelling Groundwater Surface Water Interaction in eWater Source
Chapter 1Into the Internet
Ch4(saving state with cookies and query strings)
Aquifer Storage and Recovery, Kelley Neumann
Introduction to PHP
eMail 101 (4) Class for Self help Virtual Senior Center
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
Chapter 10 Synchronous Communication
Ad

Similar to Ch5(ms access with php) (8)

PPT
Asp #2
PDF
Db connection to qtp
PPTX
3-Chapter-Edit.pptx debre tabour university
PPTX
chapter_Seven Database manipulation using php.pptx
PPTX
Chapter vii(accessing databases with jdbc)
DOC
Qtp script to connect access database
PPTX
Data base connectivity and flex grid in vb
PDF
The Ring programming language version 1.5.4 book - Part 28 of 185
Asp #2
Db connection to qtp
3-Chapter-Edit.pptx debre tabour university
chapter_Seven Database manipulation using php.pptx
Chapter vii(accessing databases with jdbc)
Qtp script to connect access database
Data base connectivity and flex grid in vb
The Ring programming language version 1.5.4 book - Part 28 of 185

More from Chhom Karath (20)

PDF
set1.pdf
PPTX
Set1.pptx
PDF
orthodontic patient education.pdf
PDF
New ton 3.pdf
PPTX
ច្បាប់ញូតុនទី៣.pptx
PPTX
Control tipping.pptx
PPTX
Bulbous loop.pptx
PPTX
brush teeth.pptx
PPTX
bracket size.pptx
PPTX
arch form KORI copy.pptx
PPTX
Bracket size
PPTX
Couple
PPTX
ច្បាប់ញូតុនទី៣
PPTX
PPTX
Shoe horn loop
PPTX
Opus loop
PPTX
V bend
PPTX
Closing loop
PPTX
Maxillary arch form
PPTX
Front face analysis
set1.pdf
Set1.pptx
orthodontic patient education.pdf
New ton 3.pdf
ច្បាប់ញូតុនទី៣.pptx
Control tipping.pptx
Bulbous loop.pptx
brush teeth.pptx
bracket size.pptx
arch form KORI copy.pptx
Bracket size
Couple
ច្បាប់ញូតុនទី៣
Shoe horn loop
Opus loop
V bend
Closing loop
Maxillary arch form
Front face analysis

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
KodekX | Application Modernization Development
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Empathic Computing: Creating Shared Understanding
KodekX | Application Modernization Development
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation theory and applications.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
sap open course for s4hana steps from ECC to s4
Mobile App Security Testing_ A Comprehensive Guide.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Ch5(ms access with php)

  • 1. How to connect to MS Access. PHP and ODBC
  • 2. // Microsoft Access • $connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=FileN ame“[, $user, $password]);
  • 3. EX: INSERT DATA <?php $db = realpath("./db1.mdb"); $conn = new COM('ADODB.Connection'); $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db"); $insert = "insert into tbProduct(ProductID, ProName, Quantity, UnitPrice) values(1, 'cc', 2,4)"; $res = $conn->Execute($insert);?> EX: DELETE <?php $db = realpath("./db1.mdb"); $conn = new COM('ADODB.Connection'); $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db"); $delete = "DELETE FROM tbProduct WHERE ProductID=4"; $res = $conn->Execute($delete); ?> EX: UPDATE <?php $db = realpath("./db1.mdb"); $conn = new COM('ADODB.Connection'); $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db"); $update = "UPDATE tbProduct SET ProName='dddd', Quantity=34, UnitPrice=5 WHERE ProductID=1"; $res = $conn->Execute($update); ?>
  • 4. EX: <?php $db_conn = new COM("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./db1.mdb").";"; $db_conn->open($connstr); $rS = $db_conn->execute("SELECT * FROM tbProduct"); $f1 = $rS->Fields(0); $f2 = $rS->Fields(1); //$rs->Fields['ProName']->Value $f3= $rS->Fields(2); $f4= $rS->Fields(3); $st="<table border=1><tr><th>ProID</th><th>ProName</th><th>Quantity</th><th>UnitPrice</th><th>Tot al</th></tr>"; while (!$rS->EOF) { $st.="<tr><td>" . $f1->value . "</td><td>" . $f2->value . "</td><td>" . $f3->value . "</td><td>" . $f4->value . "$</td><td>" . ($f4->value)*($f3->value) . "$</td></tr>"; $rS->MoveNext(); } $st.="</table>"; print $st; $rS->Close(); $db_conn->Close(); ?>
  • 5. • It is easy if you run Web Server on Widows PC. • Windows 2000, XP, Vista ODBC located inside Administrative Tools folder. Double click ODBC Data Sources. ODBC Data Source Administrator window displays.
  • 6. EX: <?php $conn=odbc_connect("dbProduct","" ,""); print('<body>'); print('<table align="center" width="90%" border=1>'); print('<tr><th>ProductID</th><th>ProductName</th><th>Quantity</th><th>UnitPrice</th><th >Total</th></tr>'); if($conn) { $sql="select * from tbProduct"; $row=odbc_exec($conn, $sql); while(odbc_fetch_row($row)){ $proID=odbc_result($row,1); $proName=odbc_result($row,2); $quantity=odbc_result($row,3); $unitPrice=odbc_result($row,4); print('<tr><td>'.$proID.'</td><td>'. $proName.'</td><td>'.$quantity.'</td><td>' . $unitPrice . '$</td><td>' . $unitPrice*$quantity . '$</td></tr>');}} print('</table>'); print('</body>'); print('</html>'); ?>

Editor's Notes

  • #8: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <style type="text/css"> .error{ background: 'red';} </style> <?php $cls1="";$cls2="";$cls3="";$cls4=""; $st=""; function clearForm() { $proID=""; $proName=""; $qty=""; $total=""; $unitprice=""; $cls=""; } if(isset($_POST['btNew'])) { clearForm(); } else if(isset($_POST['btSearch'])) { $db_conn = new COM("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./db1.mdb").";"; $db_conn->open($connstr); $rS = $db_conn->execute("SELECT * FROM tbProduct WHERE ProductID=" . $_POST['txtPID']); $f1 = $rS->Fields(0); $f2 = $rS->Fields(1); //$rs->Fields['ProName']->Value $f3= $rS->Fields(2); $f4= $rS->Fields(3); $st="<table border=1><tr><th>ProID</th><th>ProName</th><th>Quantity</th><th>UnitPrice</th><th>Total</th></tr>"; while (!$rS->EOF) { $st.="<tr><td>" . $f1->value . "</td><td>" . $f2->value . "</td><td>" . $f3->value . "</td><td>" . $f4->value . "$</td><td>" . ($f4->value)*($f3->value) . "$</td></tr>"; $rS->MoveNext(); } $st.="</table>"; $rS->Close(); $db_conn->Close(); } else if(isset($_POST['btShow'])) { $db_conn = new COM("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./db1.mdb").";"; $db_conn->open($connstr); $rS = $db_conn->execute("SELECT * FROM tbProduct"); $f1 = $rS->Fields(0); $f2 = $rS->Fields(1); //$rs->Fields['ProName']->Value $f3= $rS->Fields(2); $f4= $rS->Fields(3); $st="<table border=1><tr><th>ProID</th><th>ProName</th><th>Quantity</th><th>UnitPrice</th><th>Total</th></tr>"; while (!$rS->EOF) { $st.="<tr><td>" . $f1->value . "</td><td>" . $f2->value . "</td><td>" . $f3->value . "</td><td>" . $f4->value . "$</td><td>" . ($f4->value)*($f3->value) . "$</td></tr>"; $rS->MoveNext(); } $st.="</table>"; $rS->Close(); $db_conn->Close(); } else if(isset($_POST['btDelete'])) { if(!empty($_POST['txtPID'])) { $db = realpath("./db1.mdb"); $conn = new COM('ADODB.Connection'); $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db"); $delete = "DELETE FROM tbProduct WHERE ProductID=" . $_POST['txtPID']; $res = $conn->Execute($delete); } } else if(isset($_POST['btInsert']) or isset($_POST['btUpdate']) or isset($_POST['btDelete'])) { $proID=$_POST['txtPID']; $proName=$_POST['txtProName']; $qty=$_POST['txtProQty']; $unitprice=$_POST['txtUnitPrice']; if(empty($_POST['txtPID'])) { $cls1="error"; } else if(empty($_POST['txtProName'])) { $cls2="error"; } else if(empty($_POST['txtProQty'])) { $cls3="error"; } else if(empty($_POST['txtUnitPrice'])) { $cls4="error"; } else if(isset($_POST['btInsert'])) { $db = realpath("./db1.mdb"); $conn = new COM('ADODB.Connection'); $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db"); $insert = "insert into tbProduct(ProductID, ProName, Quantity, UnitPrice) values(" . $_POST['txtPID'] . ",'" . $_POST['txtProName'] . "'," . $_POST['txtProQty'] . "," . $_POST['txtUnitPrice'] . ")"; $res = $conn->Execute($insert); } else if(isset($_POST['btUpdate'])) { $db = realpath("./db1.mdb"); $conn = new COM('ADODB.Connection'); $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db"); $update = "UPDATE tbProduct SET ProName='" . $_POST['txtProName'] . "', Quantity=" . $_POST['txtProQty'] . ",UnitPrice=" . $_POST['txtUnitPrice'] . " WHERE ProductID=" . $_POST['txtPID']; $res = $conn->Execute($update); } } ?> </head> <body> <form method="post" action=""> <table> <tr><td><label for="txtPID" class="<?php print $cls1; ?>">ProID:</label></td><td><input type="text" name="txtPID" value="<?php print $_POST['txtPID']; ?>"/></td><td><input type="submit" name="btNew" value="New"/><input type="submit" name="btSearch" value="SeachID"/></td></tr> <tr><td><label for="txtProName" class="<?php print $cls2; ?>">ProNAME:</label></td><td><input type="text" name="txtProName" value="<?php print $_POST['txtProName']; ?>"/></td><td><input type="submit" name="btInsert" value="Insert"/></td></tr> <tr><td><label for="txtProQty" class="<?php print $cls3; ?>">QTY :</label></td><td><input type="text" name="txtProQty" value="<?php print $_POST['txtProQty']; ?>"/></td><td><input type="submit" name="btUpdate" value="Update"/></td></tr> <tr><td><label for="txtUnitPrice" class="<?php print $_POST['txtUnitPrice']; ?>">Unit price :</label></td><td><input type="text" name="txtUnitPrice" value="<?php print $_POST['txtUnitPrice']; ?>"/></td><td><input type="submit" name="btDelete" value="Delete"/></td></tr> <tr><td><label for="txtTotal">Total :</label></td><td ><input type="text" name="txtTotal" value="<?php print $total; ?>"/></td><td><input type="submit" name="btShow" value="Show data"/></td></tr> </table> <?php print $st; ?> </form> </body> </html>