problems generating a WebService

0

server.php

    require_once('DB.php');

$uri = "http://localhost/dwes18/distancia/E7/version1/web2";
$server = new SoapServer(null, array('uri' => $uri));

$server->setClass("DB");
$server->handle();

cliente.php

    header('Content-Type: text/html; charset=UTF-8');

$url = "http://localhost/dwes18/distancia/E7/version1/web2/server.php";
$uri = "http://localhost/dwes18/distancia/E7/version1/web2";


    $cliente = new SoapClient(null, array('encoding'=>'UTF8','location' => $url, 'uri' => $uri));

    $nombre = $cliente->getSaberNombre('IAWASIR');

and DB.php class

class DB {

    public function getSaberNombre($cod) {
        $nombre = null;
        try {
            $dwes = new PDO("mysql:host=127.0.0.1;dbname=agl", "root", "");
            $dwes->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (PDOException $e) {
            $nombre = -($e->getCode());
            return $nombre;
        }
        if (!isset($error)) {
            $sql = "SELECT nombre FROM modulo WHERE cod='$cod'";
            $resultado = $dwes->query($sql);
            if ($resultado) {
                $row = $resultado->fetch();
                $nombre = $row['nombre'];
            }
        }
        return $nombre;
    }





}

and it only gives me this error

  

SoapFault exception: [SOAP-ENV: Server] SOAP-ERROR: Encoding: string   'Implantation \ xf3 ...' is not a valid utf-8 string in   C: \ xampp \ htdocs \ dwes18 \ distance \ E7 \ version1 \ web1 \ client.php: 12 Stack   trace: # 0   C: \ xampp \ htdocs \ dwes18 \ distance \ E7 \ version1 \ web1 \ client.php (12):   SoapClient-> __ call ('getSaberName', Array) # 1 {main}

Any ideas?

    
asked by mantamusica 31.01.2018 в 15:59
source

1 answer

-1

solution found

As easy as adding enough options to the variable $ options so that the data does not cause an exception.

public function getSaberNombre($cod) {
    $nombre = null;
    try {

        $opciones = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
        $dwes = new PDO("mysql:host=127.0.0.1;dbname=agl2", "root", "", $opciones);
        $dwes->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch (PDOException $e) {
        $nombre = -($e->getCode());
        return $nombre;
    }
    if (!isset($error)) {
        $sql = "SELECT nombre FROM modulo WHERE cod='$cod'";
        $resultado = $dwes->query($sql);
        if ($resultado) {
            $row = $resultado->fetch();
            $nombre = $row['nombre'];
        }
    }
    return $nombre;
}
    
answered by 01.02.2018 в 16:19