Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP Manual > Examples - Examples





ลองใช้ค้นหาข้อมูล


   
Bookmark.

Examples

Example #1 Basic query

<?php

  $conn 
oci_connect('hr''hr''orcl');
  if (!
$conn) {
    
$e oci_error();
    print 
htmlentities($e['message']);
    exit;
  }

  
$query 'SELECT * FROM DEPARTMENTS';

  
$stid oci_parse($conn$query);
  if (!
$stid) {
    
$e oci_error($conn);
    print 
htmlentities($e['message']);
    exit;
  }

  
$r oci_execute($stidOCI_DEFAULT);
  if (!
$r) {
    
$e oci_error($stid);
    echo 
htmlentities($e['message']);
    exit;
  }

  print 
'<table border="1">';
  while (
$row oci_fetch_array($stidOCI_RETURN_NULLS)) {
    print 
'<tr>';
       foreach (
$row as $item) {
         print 
'<td>'.($item?htmlentities($item):'&nbsp;').'</td>';
       }
       print 
'</tr>';
  }
  print 
'</table>';

  
oci_close($conn);
?>

Example #2 Insert with bind variables

<?php

  
// Before running, create the table:
  //   CREATE TABLE MYTABLE (mid NUMBER, myd VARCHAR2(20));

  
$conn oci_connect('scott''tiger''orcl');

  
$query 'INSERT INTO MYTABLE VALUES(:myid, :mydata)';

  
$stid oci_parse($conn$query);

  
$id 60;
  
$data 'Some data';

  
oci_bind_by_name($stid':myid'$id);
  
oci_bind_by_name($stid':mydata'$data);

  
$r oci_execute($stid);

  if (
$r)
    print 
"One row inserted";

  
oci_close($conn);

?>

Example #3 Inserting data into a CLOB column

<?php

// Before running, create the table:
//     CREATE TABLE MYTABLE (mykey NUMBER, myclob CLOB);

$conn oci_connect('scott''tiger''orcl');

$mykey 12343;  // arbitrary key for this example;

$sql "INSERT INTO mytable (mykey, myclob)
        VALUES (:mykey, EMPTY_CLOB())
        RETURNING myclob INTO :myclob"
;

$stid oci_parse($conn$sql);
$clob oci_new_descriptor($connOCI_D_LOB);
oci_bind_by_name($stid":mykey"$mykey5);
oci_bind_by_name($stid":myclob"$clob, -1OCI_B_CLOB);
oci_execute($stidOCI_DEFAULT);
$clob->save("A very long string");

oci_commit($conn);

// Fetching CLOB data

$query 'SELECT myclob FROM mytable WHERE mykey = :mykey';

$stid oci_parse ($conn$query);
oci_bind_by_name($stid":mykey"$mykey5);
oci_execute($stidOCI_DEFAULT);

print 
'<table border="1">';
while (
$row oci_fetch_array($stidOCI_ASSOC)) {
  
$result $row['MYCLOB']->load();
  print 
'<tr><td>'.$result.'</td></tr>';
}
print 
'</table>';

?>

You can easily access stored procedures in the same way as you would from the command line.

Example #4 Using Stored Procedures

<?php
// by webmaster at remoterealty dot com
$sth oci_parse($dbh"begin sp_newaddress( :address_id, '$firstname',
 '$lastname', '$company', '$address1', '$address2', '$city', '$state',
 '$postalcode', '$country', :error_code );end;"
);

// This calls stored procedure sp_newaddress, with :address_id being an
// in/out variable and :error_code being an out variable.
// Then you do the binding:

   
oci_bind_by_name($sth":address_id"$addr_id10);
   
oci_bind_by_name($sth":error_code"$errorcode10);
   
oci_execute($sth);

?>



ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่