SlideShare a Scribd company logo
Crash Course to
  SQL in PHP
     Will Eder
    John Hilliard
Database Connection
  Database Conection
<?php
  $conndb
  ="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orchestra.csela
  b.nd.edu)(port=1521))(CONNECT_DATA=(SID=PROJECTS)))";

     $c1 = OCILogon("USERID", "USERPASSWORD", $conndb);

     Database Disconnection
     OCILogoff($c1);

     Database Commit
     OCICommit($c1);
?>
Insert into Table
<?
if($type == 'cust'){
    $insert_stmt = OCIParse($c1,"insert into CUSTOMER
         values('$ID','$Name','$City','$Country','$BegBal','$CurrBal')");
OCIExecute($insert_stmt);
?>
Update Table
<?
  $update_stmt = OCIParse($c1,"update CUSTOMER
                         set cust_name='".$cust."',
                                city='".$city."',
                                country='".$country."',
                                beg_bal=".$beg_bal.",
                                cur_bal=".$cur_bal."
                                where cust_id=".$cid);
  $print_stmt = "Customer $cust successfully updated.";
  OCIExecute($update_stmt);
  OCICommit($c1);
?>
Delete Item from Table
<?
  $stmtdelete = OCIParse($c1,"delete from CUSTOMER
                 where cust_id=".$cid);
  OCIExecute($stmtdelete);
  OCICommit($c1);
?>
Simple Table Query
<td align="left" bgcolor="red">
<?
if($type == 'cust') {
 $q1 = "select * from CUSTOMER";
 $s1 = OCIParse($c1,$q1);
 OCIDefineByName($s1,"CUST_ID",$cust_id);
 OCIDefineByName($s1,"CUST_NAME",$cust_name);
 OCIDefineByName($s1,"CITY",$city);
 OCIDefineByName($s1,"COUNTRY",$country);
 OCIDefineByName($s1,"BEG_BAL",$beg_bal);
 OCIDefineByName($s1,"CUR_BAL",$cur_bal);
 OCIExecute($s1);
?>
<table><h2 align="center">Customer Table</h2>
<tr>
  <th align="left">ID</th> <th align="left">Name</th> <th align="left">City</th>
  <th align="left">Country</th> <th align="left">Beginning Bal.</th> <th align="left">Current
     Bal.</th>
</tr>
<?
while(OCIFetch($s1)){
?>
<tr>
  <td><? print("$cust_id"); ?></td><td><? print("$cust_name"); ?></td><td><? print("$city"); ?></td>
  <td><? print("$country"); ?></td><td><? print("$beg_bal"); ?></td><td><? print("$cur_bal"); ?></td>
</tr>
<? } ?></table></td>

More Related Content

What's hot

20. CodeIgniter edit images
20. CodeIgniter edit images20. CodeIgniter edit images
20. CodeIgniter edit images
Razvan Raducanu, PhD
 
C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample PhpJH Lee
 
次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介
純生 野田
 
PowerCMS X
PowerCMS XPowerCMS X
PowerCMS X
純生 野田
 
IsTrue(true)?
IsTrue(true)?IsTrue(true)?
IsTrue(true)?
David Golden
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Lorna Mitchell
 
PhoneGap: Local Storage
PhoneGap: Local StoragePhoneGap: Local Storage
PhoneGap: Local Storage
Ivano Malavolta
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)
Dennis Knochenwefel
 
6. hello popescu 2
6. hello popescu 26. hello popescu 2
6. hello popescu 2
Razvan Raducanu, PhD
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
Yusuke Wada
 
ES2015 New Features
ES2015 New FeaturesES2015 New Features
ES2015 New Features
Giacomo Zinetti
 
Oh, you’re the NY times guy
Oh, you’re the NY times guyOh, you’re the NY times guy
Oh, you’re the NY times guy
David Hayes
 
7. copy1
7. copy17. copy1
Open Selector
Open SelectorOpen Selector
Open Selectorjjdelc
 
Perl使いの国のRubyist
Perl使いの国のRubyistPerl使いの国のRubyist
Perl使いの国のRubyist
Takafumi ONAKA
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHP
Sharon Levy
 

What's hot (20)

Coding website
Coding websiteCoding website
Coding website
 
20. CodeIgniter edit images
20. CodeIgniter edit images20. CodeIgniter edit images
20. CodeIgniter edit images
 
C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample Php
 
次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介
 
PowerCMS X
PowerCMS XPowerCMS X
PowerCMS X
 
IsTrue(true)?
IsTrue(true)?IsTrue(true)?
IsTrue(true)?
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
PhoneGap: Local Storage
PhoneGap: Local StoragePhoneGap: Local Storage
PhoneGap: Local Storage
 
distill
distilldistill
distill
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)
 
6. hello popescu 2
6. hello popescu 26. hello popescu 2
6. hello popescu 2
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
 
ES2015 New Features
ES2015 New FeaturesES2015 New Features
ES2015 New Features
 
Oh, you’re the NY times guy
Oh, you’re the NY times guyOh, you’re the NY times guy
Oh, you’re the NY times guy
 
7. copy1
7. copy17. copy1
7. copy1
 
Open Selector
Open SelectorOpen Selector
Open Selector
 
Perl使いの国のRubyist
Perl使いの国のRubyistPerl使いの国のRubyist
Perl使いの国のRubyist
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHP
 
Facebook
FacebookFacebook
Facebook
 
Php if
Php ifPhp if
Php if
 

Similar to Crash Course to SQL in PHP

Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
Vic Metcalfe
 
This what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfThis what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdf
kavithaarp
 
c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing
Swakriti Rathore
 
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
Mateusz Zalewski
 
Presentation1
Presentation1Presentation1
Presentation1
Rahadyan Gusti
 
"Coffee Script" in Brief
"Coffee Script" in Brief"Coffee Script" in Brief
"Coffee Script" in Brief
Nat Weerawan
 
BUS 225 Air Transporstation SupEMPLOYEE IDDATE OF HIREDEPARTMENTPE
BUS 225 Air Transporstation SupEMPLOYEE IDDATE OF HIREDEPARTMENTPEBUS 225 Air Transporstation SupEMPLOYEE IDDATE OF HIREDEPARTMENTPE
BUS 225 Air Transporstation SupEMPLOYEE IDDATE OF HIREDEPARTMENTPE
VannaSchrader3
 
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze..."Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
Mateusz Zalewski
 
Gta v savegame
Gta v savegameGta v savegame
Gta v savegame
hozayfa999
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
Sam Hennessy
 
Còdigo fuente
Còdigo fuenteCòdigo fuente
Còdigo fuente
JANIXYO
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
Hugo Hamon
 
Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]
Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]
Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]
MongoDB
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
pratikbakane
 
10...ish things i learned from programming an e-shop for a year
10...ish things i learned from programming an e-shop for a year10...ish things i learned from programming an e-shop for a year
10...ish things i learned from programming an e-shop for a year
Ines Panker
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Alessandro Nadalin
 

Similar to Crash Course to SQL in PHP (20)

Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
This what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfThis what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdf
 
c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing
 
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
 
Presentation1
Presentation1Presentation1
Presentation1
 
"Coffee Script" in Brief
"Coffee Script" in Brief"Coffee Script" in Brief
"Coffee Script" in Brief
 
BUS 225 Air Transporstation SupEMPLOYEE IDDATE OF HIREDEPARTMENTPE
BUS 225 Air Transporstation SupEMPLOYEE IDDATE OF HIREDEPARTMENTPEBUS 225 Air Transporstation SupEMPLOYEE IDDATE OF HIREDEPARTMENTPE
BUS 225 Air Transporstation SupEMPLOYEE IDDATE OF HIREDEPARTMENTPE
 
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze..."Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
"Kto to pisał?!... A, to ja.", czyli sposoby, żeby znienawidzić siebie z prze...
 
Gta v savegame
Gta v savegameGta v savegame
Gta v savegame
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Còdigo fuente
Còdigo fuenteCòdigo fuente
Còdigo fuente
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]
Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]
Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Include
IncludeInclude
Include
 
10...ish things i learned from programming an e-shop for a year
10...ish things i learned from programming an e-shop for a year10...ish things i learned from programming an e-shop for a year
10...ish things i learned from programming an e-shop for a year
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 
XQuery Rocks
XQuery RocksXQuery Rocks
XQuery Rocks
 

More from webhostingguy

Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Frameworkwebhostingguy
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guidewebhostingguy
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3webhostingguy
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serverswebhostingguy
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidationwebhostingguy
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreementwebhostingguy
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...webhostingguy
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...webhostingguy
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructurewebhostingguy
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.pptwebhostingguy
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy webhostingguy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandiserswebhostingguy
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Productswebhostingguy
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mbwebhostingguy
 

More from webhostingguy (20)

File Upload
File UploadFile Upload
File Upload
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Framework
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guide
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web servers
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidation
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreement
 
Notes8
Notes8Notes8
Notes8
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructure
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.ppt
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandisers
 
OLUG_xen.ppt
OLUG_xen.pptOLUG_xen.ppt
OLUG_xen.ppt
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Products
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mb
 
Reseller's Guide
Reseller's GuideReseller's Guide
Reseller's Guide
 

Crash Course to SQL in PHP

  • 1. Crash Course to SQL in PHP Will Eder John Hilliard
  • 2. Database Connection Database Conection <?php $conndb ="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orchestra.csela b.nd.edu)(port=1521))(CONNECT_DATA=(SID=PROJECTS)))"; $c1 = OCILogon("USERID", "USERPASSWORD", $conndb); Database Disconnection OCILogoff($c1); Database Commit OCICommit($c1); ?>
  • 3. Insert into Table <? if($type == 'cust'){ $insert_stmt = OCIParse($c1,"insert into CUSTOMER values('$ID','$Name','$City','$Country','$BegBal','$CurrBal')"); OCIExecute($insert_stmt); ?>
  • 4. Update Table <? $update_stmt = OCIParse($c1,"update CUSTOMER set cust_name='".$cust."', city='".$city."', country='".$country."', beg_bal=".$beg_bal.", cur_bal=".$cur_bal." where cust_id=".$cid); $print_stmt = "Customer $cust successfully updated."; OCIExecute($update_stmt); OCICommit($c1); ?>
  • 5. Delete Item from Table <? $stmtdelete = OCIParse($c1,"delete from CUSTOMER where cust_id=".$cid); OCIExecute($stmtdelete); OCICommit($c1); ?>
  • 6. Simple Table Query <td align="left" bgcolor="red"> <? if($type == 'cust') { $q1 = "select * from CUSTOMER"; $s1 = OCIParse($c1,$q1); OCIDefineByName($s1,"CUST_ID",$cust_id); OCIDefineByName($s1,"CUST_NAME",$cust_name); OCIDefineByName($s1,"CITY",$city); OCIDefineByName($s1,"COUNTRY",$country); OCIDefineByName($s1,"BEG_BAL",$beg_bal); OCIDefineByName($s1,"CUR_BAL",$cur_bal); OCIExecute($s1); ?> <table><h2 align="center">Customer Table</h2> <tr> <th align="left">ID</th> <th align="left">Name</th> <th align="left">City</th> <th align="left">Country</th> <th align="left">Beginning Bal.</th> <th align="left">Current Bal.</th> </tr> <? while(OCIFetch($s1)){ ?> <tr> <td><? print("$cust_id"); ?></td><td><? print("$cust_name"); ?></td><td><? print("$city"); ?></td> <td><? print("$country"); ?></td><td><? print("$beg_bal"); ?></td><td><? print("$cur_bal"); ?></td> </tr> <? } ?></table></td>