...
Code Block |
---|
<?php define("MAX", 10); define("DB", "S100450A"); define("USER", "QPGMRuser"); define("PASS", "password"); $records = array(); $query = ""; $limit = 0; if (isset($_REQUEST["query"])) $query = $_REQUEST["query"]; if (isset($_REQUEST["limit"])) $limit = intval($_REQUEST["limit"]); if ($query != "") { $query = strtoupper($query) . "%"; if ($limit == 0 || $limit > MAX) $limit = MAX; // Example of error reporting. $con = db2_connect(DB, USER, PASS, array("i5_naming" => DB2_I5_NAMING_ON)); if (!$con) { $response = array( "success" => false, "errorId" => db2_conn_error(), "errorText" => db2_conn_errormsg() ); print json_encode($response); return; } // The following will not be error checked, for brevity. $stm = "select distinct pname, prid from rpgspcart/prodp where pname like ? order by pname"; $stm = db2_prepare($con, $stm); db2_bind_param($stm, 1, "query", DB2_PARAM_IN, DB2_CHAR); db2_execute($stm); $count = 0; while (db2_fetch_row($stm) && $count < $limit) { $record = array(); $record["PNAME"] = trim(db2_result($stm, "PNAME")); $record["PRID"] = trim(db2_result($stm, "PRID")); $records[$count++] = $record; } } // "colWidths" is optional, this helps the widget to // size the columns when multiple fields are displayed. $return = array( "success" => true, "response" => array ( "results" => $records, "colWidths" => array( db2_field_precision($stm, "PNAME"), db2_field_precision($stm, "PRID") ) ) ); print json_encode($return); ?> |