<?php function getQuote($fpsecode) { global $dbh; $result = array(); try { $query = "SELECT fprice, fcansale, fbalance, fbaltip FROM tblbalance where upper(trim(fpsecode)) = :psecode limit 1"; $stmt = $dbh->prepare($query); $stmt->execute(array(’:psecode’ => strtoupper(trim($fpsecode)))); $stmt->bindColumn(’fprice’, $fprice); $stmt->bindColumn(’fcansale’, $fcansale); $stmt->bindColumn(’fbalance’, $fbalance); $stmt->bindColumn(’fbaltip’, $fbaltip); while($row = $stmt->fetch(PDO_FETCH_BOUND)) { // } } catch (PDOException $e) { echo $e->getMessage(); } return $fprice; //你可以返回一个数组 } $dsn = ’pgsql:host=192.168.*.* port=5432 dbname=db user=123456 password=123456’; try { $dbh = new PDO($dsn); } catch (PDOException $e) { die(’Connection failed: ’ . $e->getMessage()); } ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache $server = new SoapServer("stockquote.wsdl"); //配置文件 $server->addFunction("getQuote"); $server->handle(); ?>
stockquote.wsdl
<?xml version =’1.0’ encoding =’UTF-8’ ?> <definitions name=’StockQuote’ targetNamespace=’http://example.org/StockQuote’ xmlns:tns=’ http://example.org/StockQuote ’ xmlns:soap=’http://schemas.xmlsoap.org/wsdl/soap/’ xmlns:xsd=’http://www.w3.org/2001/XMLSchema’ xmlns:soapenc=’http://schemas.xmlsoap.org/soap/encoding/’ xmlns:wsdl=’http://schemas.xmlsoap.org/wsdl/’ xmlns=’http://schemas.xmlsoap.org/wsdl/’>
<message name=’getQuoteRequest’> <part name=’symbol’ type=’xsd:string’/> </message> <message name=’getQuoteResponse’> <part name=’Result’ type=’xsd:float’/> </message>
<portType name=’StockQuotePortType’> <operation name=’getQuote’> <input message=’tns:getQuoteRequest’/> <output message=’tns:getQuoteResponse’/> </operation> </portType>
<binding name=’StockQuoteBinding’ type=’tns:StockQuotePortType’> <soap:binding style=’rpc’ transport=’http://schemas.xmlsoap.org/soap/http’/> <operation name=’getQuote’> <soap:operation soapAction=’urn:xmethods-delayed-quotes#getQuote’/> <input> <soap:body use=’encoded’ namespace=’urn:xmethods-delayed-quotes’ encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/> </input> <output> <soap:body use=’encoded’ namespace=’urn:xmethods-delayed-quotes’ encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/> </output> </operation> </binding>
<service name=’StockQuoteService’> <port name=’StockQuotePort’ binding=’StockQuoteBinding’> <soap:address location=’http://192.168.3.9/php5/server.php’/> </port> </service> </definitions> |
PHP之友评论