一个soap传输webservice框架(服务端)
程序员文章站
2022-05-01 15:53:14
...
需要手动在common文件夹下建立一个configure.wsdl文件 api文件夹是webservice接口。 common文件夹是常用方法、以及类库。 user/admin.php里面设置登录密码 server.php是服务端 目前wsdl在程序中自动生成 无 ?phpdate_default_timezone_set ( 'PRC' );$functio
需要手动在common文件夹下建立一个configure.wsdl文件
api文件夹是webservice接口。
common文件夹是常用方法、以及类库。
user/admin.php里面设置登录密码
server.php是服务端
目前wsdl在程序中自动生成
"; $message = ""; $port = " "; $file = fopen("common/configure.wsdl","w"); fwrite($file, $wsdl); fclose($file); $db = new db(); $service = new SoapServer('common/configure.wsdl'); $service->addFunction($functions); $service->handle();"; $binding = " "; $binding .= ""; $wsdl .= $message.$port.$binding.""; foreach ($function as $name => $parts){ $message .= " "; foreach ($parts as $part => $type){ $message .= " "; } $message .= " "; $port .= " "; $binding .= " "; $functions[] = $name; } $port .= "
'string', 'pwd' => 'string'); function admin($user, $pwd){ if ($user === 'root' && $pwd =='123456') { return '1'; }else { return '0'; } }
query("set names utf8"); } /** * * @return boolean */ function ping(){ return self::$_mysqli->ping(); } /** * * @param 需要插入或者更新的参数键值对 $args * @return 一个字符串,需要插入或者更新的字段 */ private function getFields($args){ $fields = ''; foreach ($args as $k=>$v){ if ($v === '') { continue; } $fields .= "`". $k ."`='". $v ."', "; } return substr($fields, 0, -2); } /** * 执行一条sql语句 */ function query($sql){ return self::$_mysqli->query($sql); } /** * * @param unknown $sql * @return unknown */ function select($sql){ self::$_stmt = $this->query($sql); if (self::$_stmt && self::$_stmt->num_rows>0) { while (@$row = self::$_stmt->fetch_assoc()){ $res[] = $row; } } self::$_stmt->free(); return $res; } function get($table, $field, $where){ $sql = "select ".$field." from ".$table." where ".$where; return $this->select($sql); } function getRow($table, $field, $where){ $sql = "select ".$field." from ".$table." where ".$where; $result = $this->select($sql); return $result[0]; } /** * 进行多条sql查询 * @param unknown $query * @return mixed */ function multi_query($query){ if (self::$_mysqli->multi_query($query)){ do { if (self::$_stmt = self::$_mysqli->store_result()) { while (@$row = self::$_stmt->fetch_row()) { $res[] = $row; } self::$_stmt->free(); } }while (self::$_mysqli->next_result()); } return $res; } /** * 向一张表插入单条记录 * @param 即将执行插入操作的表 $table * @param 插入字段名和字段值的键值对 $args * @param 如果设置,sql语句 * @return 插入结果 */ function add($table, $types, $args, $flag=false){ if (self::$_stmt) { $this->emptystmt(); } $fields = ""; $values = ""; $bind = 'self::$_stmt->bind_param('.$types; foreach ($args as $k=>$v){ $fields .= $k.", "; $values .= "?,"; $bind .= ' , $'.$k; $$k = $v; } $bind .= ');'; $fields = substr($fields, 0, -2); $values = substr($values, 0, -1); $sql = "insert into ".$table." (".$fields.") values (".$values.")"; self::$_stmt = self::$_mysqli->prepare($sql); echo $cId; self::$_stmt->bind_param(iis , $cId , $pId , $createDate); //eval($bind); $res = self::$_stmt->execute(); if ($flag) { $this->emptystmt(); } return $res; } /** * 向一张表删除符合条件的记录 * @param 执行删除操作的表名 $table * @param 符合要求的条件 $where * @return 删除结果 */ function del($table, $where, $flag = false){ if (self::$_stmt) { $this->emptystmt(); } $sql = "delete from ".$table." where ".$where; self::$_stmt = self::$_mysqli->prepare($sql); $res = self::$_stmt->execute(); if ($flag) { $this->emptystmt(); } return $res; } /** * 向一张表进行更新操作 * @param 执行更新操作的表名 $table * @param 插入字段名和字段值的键值对 $args * @param 符合要求的条件 $where * @return 更新结果 */ function update($table, $types, $args, $where, $flag = false){ if (self::$_stmt) { $this->emptystmt(); } $fields = ""; $values = ""; $bind = 'self::$_stmt->bind_param(\''.$types.'\''; foreach ($args as $k=>$v){ $fields .= $k."=?, "; $bind .= ' , $'.$k; $$k = $v; } $bind .= ');'; $fields = substr($fields, 0, -2); $values = substr($values, 0, -1); $sql = "update ".$table." set ".$fields." where ".$where; self::$_stmt = self::$_mysqli->prepare($sql); if (eval($bind)){ $res = self::$_stmt->execute(); } if ($flag) { $this->emptystmt(); } return $res; } function bind($types, $args, $flag = false){ if (self::$_stmt) { $bind = 'self::$_stmt->bind_param('.$types; foreach ($args as $k => $v){ $bind .= ' , $'.$k; $$k = $v; } $bind .= ');'; if (eval($bind)){ $res = self::$_stmt->execute(); } if ($flag) { $this->emptystmt(); } return $res; } return false; } /** * 关闭与准备语句 */ function emptystmt(){ self::$_stmt->close(); } /** * 析构函数 */ function __destruct(){ self::$_mysqli->close(); } }
'string', 'param1' => 'int'); function Example($param0, $param1){ global $db; $info = array ($param0, $param1); return json_encode($info); }
上一篇: ThinkPHP中应用FCK有关问题
下一篇: MySQL参数设置如何解决瓶颈效应?
推荐阅读