为什么我的SOAP XML会不断更改我通过方法编写的值?

时间:2018-02-06 13:16:58

标签: php xml web-services soap

实际上正在开发一个非常基本的Web服务(初学者),我已经遇到了一些PHP方法的问题(在不使用web服务的情况下工作得非常好),这应该允许我在数据库中更改一行表

例如,我收到了来自我的网络服务的请求:

UPDATE tbl_rattachement_sdis_communes SET trigramme_service=?,code_insee=? WHERE id_service=?Array ( [0] => 0 [1] => 40000 [2] => 768 )

我应该:

UPDATE tbl_rattachement_sdis_communes SET trigramme_service=?,code_insee=? WHERE id_service=?Array ( [0] => "TST" [1] => 40000 [2] => 768 )

所以这是我的PHP方法:

public  function setRequeteModifier($obj)
{
    $classe=get_class($obj);
    $table = $classe;
    $proprietes=$obj->getProprietes();
    $where = " WHERE ";
    $params = array();
    $sql="UPDATE $table SET "; 
    $id="";
    foreach($proprietes as $key=>$val)
    {

        if(($key != "id_".$classe) && 
          ($key != "id_".get_parent_class($obj)) && 
          ($key !="id_row") && 
          ($key !="id_hydroweb") && 
          ($key !="id_profil") && 
          ($key !="id_service") && 
          ($key !="id_login_sdis") && 
          ($key !="id_cis") && 
          ($key !="id_login_ext"))
        {
                $sql=$sql.$key."=?,"; 
                $params[]=$val;
        }
        else
        {
                $where = $where.$key."=?"; 
                $id=$val;
        }
    }
    $proprietes= $val;
    $params[]=$val;
    // $params[] = $id; 

    $sql = rtrim($sql, ","); 
    $sql = $sql . $where; 
    $this->requete = $sql; 
    $this->parametres = $params;
 }
 public function setPSModifier($obj)
 {

    $nomps=self::$_appel." modifier". get_class($obj). " " . substr(self::$_syntaxe,0,1);//Appel et nom de la procedure stockée
    $proprietes=$obj->getProprietes();
    try
    {
        $i=0;
        $params = array();
        foreach($proprietes as $key=>$val)
        {   
            $nomps = $nomps. "?,"; 
            $params[] = $val;
        }
        $nomps = rtrim($nomps, ",");
        $nomps = $nomps . substr(self::$_syntaxe,1,1);
        $this->requete = $nomps;
        $this->parametres = array();
        $this->parametres = $params;
    }
    catch (PDOException $e)
    {
        throw new PDO3Exception($e->code);
    }
}

该课程与上述课程相关联:

function __autoload($class_name) { // charge les fichiers des classes à la demande

    $path=dirname(__FILE__);

    if(file_exists($path . '/'.$class_name.'.class.php'))
    {
        //cas des classes de PDO3
        include_once mb_strtolower ($path . '/'.$class_name.'.class.php'); //exemple de fichier pdo3.class.php
    }
        //cas des classes métier qui se trouvent dans un dossier metier
    if(file_exists($path . '/../metier/'.$class_name.'.class.php'))
    {
        include_once mb_strtolower ($path . '/../metier/'.$class_name.'.class.php'); //exemple de fichier client.class.php
    }

    //cas des classes du webservice qui se trouvent dans un dossier service
    if(file_exists($path . '/../service/'.$class_name.'.class.php'))
    {
        include_once mb_strtolower ($path . '/../service/'.$class_name.'.class.php'); //exemple de fichier client.class.php
    }

class Gestion
{
    public function __construct()
    {

    }
    static public function modifier($obj,$ps=false) //true si ps
    {
        $classe=get_class($obj);
        try
        {
            $pdo = PDO3::getInstance();
            if($ps===true) //procédure stockée
            {
                $pdo->setPSModifier($obj);
            }
            else //requête SQL
            {
                $pdo->setRequeteModifier($obj);
            }
            $sql=$pdo->getRequete();
            echo $sql;
            $params = $pdo->getParametres();
            print_r($params);
            $stmt =$pdo->prepare($sql);
            $resultat = $stmt->execute($params);
            return $resultat;
            $stmt=null;
            $pdo = NULL;
        }
        catch (PDOException $e)
        {
            throw new PDO3Exception( $e->getCode(), $classe);
            return 0;
        }
    }
}

这是我的php类:

class tbl_rattachement_sdis_communes extends Modele implements IProprietes
{
    protected $trigramme_service, $code_insee, $id_service;

    public function __construct($trigramme_service= null, $code_insee= null, $id_service= null)
    {
        if(!($trigramme_service== null && $code_insee== null && $id_service== null))
        {
            $this->trigramme_service = $trigramme_service;
            $this->code_insee = $code_insee;
            $this->id_service = $id_service;
        }
    }
    public function getProprietes()
    {
        return get_object_vars($this);
    }
}

?>

这是我的php全局类:

class hydroweb
{
public function modifierUnRattachement ($id_service, $trigramme_service, $code_insee)
    {
        $rattach = new tbl_rattachement_sdis_communes($trigramme_service, $code_insee, $id_service);
        Gestion::modifier($rattach);
    }
 }

SOAP XML部分:

<message name="modifierUnRattachementRequest">
    <part name="trigramme_service" type="xsd:string"/>
    <part name="code_insee" type="xsd:int"/>
    <part name="id_service" type="xsd:int"/>
</message>
<message name="modifierUnRattachementResponse"> 
</message>




<operation name="modifierUnRattachement">
    <documentation>Modifier un Rattachement SDIS / Commune : </documentation>
    <input message="typens:modifierUnRattachementRequest"/>
    <output message="typens:modifierUnRattachementResponse"/>
</operation>





<operation name="modifierUnRattachement">
    <soap:operation soapAction="urn:modifierUnRattachement"/>
    <input>  
    <soap:body namespace="http://localhost/webservice/service/hydroweb.wsdl" use="encoded"   
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>  
    </input>  
    <output>
    <soap:body namespace="http://localhost/webservice/service/hydroweb.wsdl" use="encoded" 
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
    </output>
</operation>





<service name="Hydroweb">
    <port name="HydrowebPortType" binding="typens:HydrowebBinding">
        <soap:address location="http://localhost/webservice/service/server.soap"/>
    </port>
</service>

最后我的客户:

require("hydroweb.wsdl");
require("hydroweb.class.php");

$client = new SoapClient('http://localhost/webservice/service/server.soap?wsdl', Array("trace"=>1, "exceptions"=>true));

try
{
    $res1 = $client->modifierUnRattachement("TST", 40000, 768);
    var_dump($res1);
}
catch(SoapFault $fault)
{
echo 'Request : <br><xmp>',
$client->__getLastRequest(), 
'</xmp><br><br> Error Message : <br>',
$client->__getLastResponse().'<br>';
}

0 个答案:

没有答案