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>

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 fromTable <? $stmtdelete = OCIParse($c1,"delete from CUSTOMER where cust_id=".$cid); OCIExecute($stmtdelete); OCICommit($c1); ?>
  • 6.
    Simple Table Query <tdalign="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>