XMLSERVICEPHP Percent
Goto Main Page
Goto PHP page
Goto Documents
If using the XMLSERVICE REST interface (xmlcgi.pgm) and having issues with percent sign ('%')
, use PHP urlencode function.
Note: The DB2 like operation requires xmlservice 1.8.4 or higher.
<?php // see connection.inc param details ... require_once('connection.inc'); // http POST parms $clobIn = " <?xml version='1.0'?> <script> <sql> <prepare>select * from DB2/animals where name like ?</prepare> <execute><parm>".urlencode("Pea%")."</parm></execute> <fetch block='all' error='fast'/> </sql> </script> "; $clobOut = ""; $postdata = http_build_query( array( 'db2' => "*LOCAL", 'uid' => $user, 'pwd' => $password, 'ipc' => $ipc, 'ctl' => $ctl, 'xmlin' => $clobIn, 'xmlout' => 4096 // size expected XML output ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); // execute $linkall = $i5resturl; $result = file_get_contents($linkall, false, $context); // result if ($result) { $getOut = simplexml_load_string($result); $clobOut = $getOut->asXML(); } else $clobOut = ""; // dump raw XML (easy test debug) var_dump($clobOut); ?>