test param:1101

From: Date: Wed, 25 Jan 2012 20:49:58 +0000
Subject: test param:1101
Groups: php.test 
Request: Send a blank email to php-test+get-917@lists.php.net to get a copy of this message
PEAR::SOAP Web Service: Kurswert einer Aktie für einen bestimmten Tag -------------------------------------------------------------------------------- Client -------------------------------------------------------------------------------- <?php // Enable Error Reporting ini_set('display_errors',1); // bind SOAP/Client.php -> path of the php file require_once "SOAP/Client.php"; // URI delivered to web service $sc = new SOAP_Client("http://localhost/server.php"); // start call function to use the function of the Web Service $parameter = array("name" => "hp","date" => "2007-05-08"); $result = $sc->call ("getValue", &$parameter, "urn:mystockserv"); // print result print $result."\n"; ?> -------------------------------------------------------------------------------- Server -------------------------------------------------------------------------------- <?php // Enable Error Reporting ini_set('display_errors',1); // bind PEAR::SOAP require_once "SOAP/Server.php"; $skiptrace =& PEAR::getStaticProperty('PEAR_Error', 'skiptrace'); $skiptrace = true; // Database-Class class mysqldb { private $db; public function __construct() { // Connect to mysql server and select database try { $this->db = new PDO ("mysql:host=localhost;dbname=database","user","password"); } catch (PDOException $e) { throw new Exception ('Connection failed: ' .$e->getMessage()); } } public function getValue ($name,$date) { // Get value data from kurs
      		$a = array();
		if (!$stmt=$this->db->prepare('SELECT preis FROM kurs WHERE name LIKE :name AND datum=:date'))
throw new Exception ('PDOStatement::prepare failed!'); if (!$stmt->bindParam(':name',$name) || !$stmt->bindParam(':date',$date)) throw new Exception ('PDOStatement::bindParam failed!'); if (!$stmt->execute()) throw new Exception ('PDOStatement::execute failed!');
                // Save data to an array
while($kurs=$stmt->fetchObject()) { array_push($a, $kurs->preis); }
                // In this example only use the first value as an result
                $result=$a[0];
// Return result return ($result); } } // Service-Class class mystockserv { // __dispatch_map public $__dispatch_map = array (); // In/Out param -> __dispatch_map public function __construct() {
    $this->__dispatch_map["getValue"] =
      array ("in" => array("name" => "string","date" => "string"),
             "out" => array("value" => "string"));
} // get back __dispatch_map in __dispatch public function __dispatch($methodname) {
    if (isset($this->__dispatch_map[$methodname])) {
      return $this->__dispatch_map[$methodname];
    }
    return NULL;
} // servicemthod with parameters function getValue ($name,$date) {
    // parameter error?
    if (($name == null) || (trim($name) == "") || ($date == null) || (trim($date) == "")) {
      // send errormessage
      return new SOAP_Fault("Parameter error","0815", "Client");
    }
    // Create new db instance
    $mysql = new mysqldb();
    // Get data from database
    $value = $mysql->getValue($name,$date);
    // return SOAP-Obj.
    return (new SOAP_Value('value','string', $value));
} } // service-class $service = new mystockserv(); // server $ss = new SOAP_Server(); // add service with name $ss->addObjectMap (&$service,"urn:mystockserv"); // postdata -> service $ss->service ($HTTP_RAW_POST_DATA); ?>

« previous php.test (#917) next »