Consulta sql con soapService
Publicado por Juan Jose (9 intervenciones) el 08/03/2017 18:06:45
Hola a todos,
Estoy empezando a utilizar los servicios con soapservice, mediante funciones sql
pero el problema lo encuentro al hacer una consulta me aparece este error:
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Call to undefined method stdClass::query() in C:\xampp\htdocs\DatosServicio\index.php:46 Stack trace: #0 C:\xampp\htdocs\DatosServicio\index.php(46): SoapClient->__call('consultaPais', Array) #1 C:\xampp\htdocs\DatosServicio\index.php(46): SoapClient->consultaPais(Object(stdClass), 'Alemania') #2 {main} thrown in C:\xampp\htdocs\DatosServicio\index.php on line 46
Bien este es el formulario en el que introduzco el nombre de un pais "Alemania" y al pulsar en el formulario se recarga y hace una consulta sql y devuelve el dato texto iso.
Index.php
ser.php
la Cuestion es que si llamo a la funcion prueba que solo retorna la palabra hola, funciona correctamente, el problema lo tengo con la funcion que llama a sql.
Como os he dicho me aparece este error:
¿Teneis alguna idea de cual puede ser el problema?
Estoy empezando a utilizar los servicios con soapservice, mediante funciones sql
pero el problema lo encuentro al hacer una consulta me aparece este error:
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Call to undefined method stdClass::query() in C:\xampp\htdocs\DatosServicio\index.php:46 Stack trace: #0 C:\xampp\htdocs\DatosServicio\index.php(46): SoapClient->__call('consultaPais', Array) #1 C:\xampp\htdocs\DatosServicio\index.php(46): SoapClient->consultaPais(Object(stdClass), 'Alemania') #2 {main} thrown in C:\xampp\htdocs\DatosServicio\index.php on line 46
Bien este es el formulario en el que introduzco el nombre de un pais "Alemania" y al pulsar en el formulario se recarga y hace una consulta sql y devuelve el dato texto iso.
Index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<html>
<head>
<meta charset="UTF-8">
<title>Servicios Paises</title>
<?php include 'configuracion.php'; ?>
</head>
<body>
<form name="tabla" method = "post" action =<?php echo $_SERVER['PHP_SELF'] ?>>
<input type="hidden" name="listar" value='0'>
<center>
<table border="1" id="tabladatos">
<tbody>
<tr text-aling="center">
<td colspan="2" ><h3>Buscar Paises</h3></td>
</tr>
<tr>
<td ><h4>Pais</h4><input type="text" name="fpais"></td>
<td><h4>Iso</h4><input type="text" name="fiso"></td>
</tr>
<tr>
<td><button type="submit">Buscar Pais</button></td>
<td><button type="submit">Buscar ISO</button></td>
</tr>
<tr>
<td colspan="2"><input type = "submit" name = "submit" value = "Listar Paises" onclick = "javascript:this.form.listar.value = 1;"></td>
</tr>
</tbody>
</table>
<?php
$url = 'http://localhost/DatosServicio/ser.php';
$uri = 'http://localhost/DatosServicio';
$cliente = new SoapClient(null, array('location' => $url, 'uri' => $uri));
//si tenemos algin dato en el campo de pais
if (isset($_POST['fpais'])) {
if (!empty($_POST['fpais'])) {
echo 'Pais';
//hacemos la conexion
$gestion = $cliente->conectar($server, $base, $usu, $pas);
//y hacemos la consulta que devolvera un solo dato (AQUI ES DONDE FALLA)
$dato = $cliente->consultaPais($gestion, $_POST['fpais']);
echo $dato;
}
}
?>
</body>
</html>
ser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class Datos {
public function conectar($server, $base, $usu, $pas) {
try {
$gestion = new PDO('mysql:host=' . $server . ';dbname=' . $base . '', '' . $usu . '', '' . $pas . '');
$gestion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
$mensajeError = $e->getMessage();
echo $mensajeError;
}
return $gestion;
}
public function consultaPais($gestion, $pais) {
if (isset($gestion)) {
try {
$sql = "SELECT iso FROM paises WHERE nombre='$pais'";
$consulta = $gestion->query($sql);
} catch (PDOException $e) {
$mensajeError = $e->getMessage();
echo $mensajeError;
}
//y devolvemos el dato
while ($resultados = $consulta->fetch()) {
$dato=$resultados['iso'] ;
}
return $dato;
}
}
public function llamada() {
return 'hola';
}
}
$uri = 'http://localhost/DatosServicio';
$server = new SoapServer(null, array('uri' => $uri));
$server->setClass('Datos');
$server->handle();
?>
la Cuestion es que si llamo a la funcion prueba que solo retorna la palabra hola, funciona correctamente, el problema lo tengo con la funcion que llama a sql.
Como os he dicho me aparece este error:
1
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Call to undefined method stdClass::query() in C:\xampp\htdocs\DatosServicio\index.php:46 Stack trace: #0 C:\xampp\htdocs\DatosServicio\index.php(46): SoapClient->__call('consultaPais', Array) #1 C:\xampp\htdocs\DatosServicio\index.php(46): SoapClient->consultaPais(Object(stdClass), 'Alemania') #2 {main} thrown in C:\xampp\htdocs\DatosServicio\index.php on line 46
¿Teneis alguna idea de cual puede ser el problema?
Valora esta pregunta
0