我用PHP写了一个webservice遇见 一个奇怪的问题。代码如下header("Content-Type:text/html;charset=utf-8");
    define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
    @include_once (S_ROOT.'./source/nusoap.php');//插入文件
    $server = new soap_server();
    $server->soap_defencoding = 'UTF-8';
    $server->configureWSDL('hellowsdl', 'urn:hellowsdl');
    $server->wsdl->schemaTargetNamespace = 'urn:hellowsdl';
    
    $server->register('hello',                 // method name
    array('tablename'=>'xsd:string','msg'=>'xsd:string'), // input parameters
    array('return' => 'xsd:string'),       // output parameters
    'urn:hellowsdl',                       // namespace
    'urn:hellowsdl#hello',                 // soapaction
    'rpc',                                 // style
    'encoded',                             // use
    'Says hello to the caller'             // documentation
    );
    
    function hello($tablename,$msg) {
          $staut = '';
    $uid = insert_msg($tablename,$msg);
    if (!empty($uid)) {
     $staut = 'ok';
    }else
{
$staut = 'error';
}
    return $staut;
    }
    function insert_msg($tablename,$msg)
     {
     $conn = mysql_pconnect("服务器地址","用户名","密码");
     $title = '优惠信息';
     mysql_select_db($tablename, $conn);
        mysql_query("INSERT INTO zwmobi_channel_content(cid,title,content,time)VALUES('18','$title','$msg',now())");
        return mysql_insert_id();
     }
    
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
    
    $server->service($HTTP_RAW_POST_DATA);问题是当我调用webservice的时候,数据库插入一条数据,但是$title $msg的信息都没有插入到数据库里面。如果我要换成字母和汉字的情况下如: mysql_query("INSERT INTO zwmobi_channel_content(cid,title,content,time)VALUES('18','123','45689999',now())");这样可以正常插入。请问高手是何道理呢?

解决方案 »

  1.   

    调用代码如下define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
        @include_once (S_ROOT.'./source/nusoap.php');//插入文件
    $proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
    $proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
    $proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
    $proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
    $client   =   new   nusoap_client('webservice地址','wsdl',$proxyhost, $proxyport, $proxyusername, $proxypassword); 
    $client->soap_defencoding = 'UTF-8';
    $client->decode_utf8 = false;
    $err = $client->getError();
    if ($err) {
    echo '接口错误';
        }
        $tablename = 'tbt';
        $msg = '这里是内容';
        $RanStr=$client->call('hello',$tablename,$msg);
        echo $RanStr;
      

  2.   

    mysql_query("INSERT INTO zwmobi_channel_content(cid,title,content,time)VALUES('18','$title','$msg',now())") or die(mysql_error());
      

  3.   

    这个应该是编码问题,或者是字段长度的问题,和webservice无关.
    插入语句之前,mysql_set_charset('utf8')一下试试.
      

  4.   

    直接
    mysql_query("INSERT INTO zwmobi_channel_content(cid,title,content,time)VALUES('18','0中文1','0中文2',now())");后,数据库里有值吗?
    有,就是编码问题了吧