连载3:利用PHP创建由Oracle驱动的SOAP服务

G鈥哸ng鈥哸

G鈥哸ng鈥哸

2016-01-29 12:56

连载3:利用PHP创建由Oracle驱动的SOAP服务,连载3:利用PHP创建由Oracle驱动的SOAP服务

《连载1:利用PHP创建由Oracle驱动的SOAP服务》

《连载2:利用PHP创建由Oracle 驱动的SOAP 服务》

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/php/)

为便于参考,下面是一个完整的 BookManager 类,以及使用该类公开 SOAP 服务的相应服务器脚本。

 <?php

/**
 * SOAP Service class to manage the books table
 *
 * @author John Coggeshall <john@zend.com
 *
 * @throws SoapFault
 */
class BookManager {
 
 private $objDB;

 const DB_USERNAME="demo";
 const DB_PASSWORD="password";
 const DB_DATABASE="myoracle";
 
 /**
  * Object Constructor: Establishes DB connection
  *
  */
 function __construct() {
  
  $this-objDB = oci_connect(self::DB_USERNAME,
                             self::DB_PASSWORD,
                             self::DB_DATABASE);
      
  if($this-objDB === false) {
   throw new SoapFault(-1, "Failed to connect to database backend (reason: " .
                                         oci_error() . ")");
  }
 }

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/php/)

 /**
  * Private method to return the DB connection and make sure it exists
  *
  * @return unknown
  */
 private function getDB() {
  if(!$this-objDB) {
   throw new SoapFault(-1, "No valid database connection");
  }
  
  return $this-objDB;
 }
 
 /**
  * Add a new book to the database
  *
  * @param string $isbn The ISBN serial number for the book (32 char max)
  * @param string $author The name of the primary author (50 char max)
  * @param string $title The title of the book (50 char max)
  * @param float $price The price of the book in USD
  *
  * @return mixed SOAP Fault on error, true on success
  */
 public function addBook($isbn, $author, $title, $price) {

  $query = "INSERT INTO books (isbn, author, title, price)
                 VALUES (:isbn, :author, :title, :price)";
  
  $stmt = oci_parse($this-getDB(), $query);
  
  if(!$stmt) {
   throw new SoapFault(-1, "Failed to prepare query (reason: "  .
                                         oci_error($stmt) . ")");
  }
  
  // The numbers 32, 50, 50 are the max column lengths
  oci_bind_by_name($stmt, "isbn", $isbn, 32);
  oci_bind_by_name($stmt, "author", $author, 50);
  oci_bind_by_name($stmt, "title", $title, 50);
  oci_bind_by_name($stmt, "price", $price);
  
  if(!oci_execute($stmt)) {
   oci_rollback($this-getDB());
   throw new SoapFault(-1, "Failed to execute query (reason: " .
                                     &nbs

展开更多 50%)
分享

猜你喜欢

连载3:利用PHP创建由Oracle驱动的SOAP服务

PHP
连载3:利用PHP创建由Oracle驱动的SOAP服务

连载1:利用PHP创建由Oracle 驱动的SOAP服务

PHP
连载1:利用PHP创建由Oracle 驱动的SOAP服务

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

连载2:利用PHP创建由Oracle 驱动的SOAP服务

PHP
连载2:利用PHP创建由Oracle 驱动的SOAP服务

连载4:利用PHP创建由Oracle驱动的SOAP服务

PHP
连载4:利用PHP创建由Oracle驱动的SOAP服务

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

利用oradim重建Oracle服务

编程语言 网络编程
利用oradim重建Oracle服务

用php实现soap通讯

PHP
用php实现soap通讯

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

C#中关于GDI+输出的问题

C#中关于GDI+输出的问题

《炉石传说》德鲁伊丛林之魂研究

《炉石传说》德鲁伊丛林之魂研究
下拉加载更多内容 ↓