Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 87
  • Last Modified:

Why can't get the rows from my webservice? What am I doing wrong?

Hello guys,

I wrote two parts: serve and client

My client doesn't display the rows from my server, I wonder if someone could point me what I am doing wrong.

this is my server:

<?php
  require_once('lib/nusoap.php');
  
  $servername = "mysql01.teachmenow1.hospedagemdesites.ws";
  $username   = "teachmenow1";
  $password   = "xxxxxxxx";
  $dbnome     = "teachmenow1";  

  $server = new soap_server();
  $server->configureWSDL("listadownloads","urn:Testing WSDL ");

  //register a function that works on server
  $server ->register('listadownloads', array('value' => 'xsd:string'), array('return' => 'xsd:string'), 'urn:server', 'urn:server#listadownloads');
  $server->register("gethelloworld",   array("name" => "xsd:string"),array("return" => "xsd:string"),"urn:helloworld","urn:helloworld#gethelloworld");

  // create the function to fetch Data’s from Database
  
	function gethelloworld($name) {
		$myname    =    "My Name Is <b>".$name . "</b>";
		return $myname;
	}

	function listadownloads ()
	{
        $conn   = $conn = new mysqli($servername, $username, $password, $dbnome);
        $result = $conn->query($sql);
		$sql    = "SELECT * FROM CADDOWNLOAD";
		  
		if ($result->num_rows > 0) {
			while($row = $result->fetch_assoc()) {
				$itens [] = array('id'=>$row['CADDOWNLOADS_ID'], 
				                  'nome'=>$row['NOME'], 
								  'cidade'=>$row['cidade']
								 );
			}				
		}  
		
		$conn->close();		
		return $itens;
	}	
  		  
		  
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
	$server ->service($HTTP_RAW_POST_DATA);
  
	
?>

Open in new window



this is my client

<?php
//Call server function

  require_once('lib/nusoap.php');

  $url = "http://teachmenow.com.br/nusoap/server.php";
  $client = new nusoap_client($url);
  
  $response = $client ->call('listadownloads');

  if($client->fault)
  {
            echo "FAULT: <p>Code: (".$client ->faultcode.")</p>";
            echo "String: ".$client->faultstring;
  }
  else
  {
            $result = $response;
            $count = count($result);
            echo "inside";
			echo $result;
?>
<table >
<tr>
            <th>Nome</th>
            <th>Cidade</th>
</tr>
<?php

    for($i = 0;$i < $count-1;$i++) 
    {
              $rowtype = ($i % 2) ? "style='background:#88DAEB'": "style=background:#FFF";
?>
<tr <?php echo $rowtype; ?>>
            <td><?php echo $result[$i]['nome']?></td>
            <td><?php echo $result[$i]['cidade']?></td>
</tr>
<?php
      }
?>
</table>
<?php
}
?>

Open in new window


Thanks a lot
Alex
0
hidrau
Asked:
hidrau
  • 5
  • 2
  • 2
  • +1
2 Solutions
 
Marco GasiFreelancerCommented:
Is the blank space in $response = $client ->call('listadownloads'); a typo? If not, it could be the cause of your issue. In this case, set error_reporting(E_ALL) to get error messages in development environment.
1
 
Mukesh YadavFull Stack DeveloperCommented:
Try this ;)

There is a problem on line no: 25 in function named "listadownloads ".

You used 4 variables here but you didn't defined in this scope I know you defined on the top of this file but you can access then inside this function without global keyword, so add do something like this:

function listadownloads ()
{
        global $servername;
        global $username;
        global $password;
        global $dbnome;
        $conn   = $conn = new mysqli($servername, $username, $password, $dbnome);

Open in new window


If you don't want to use global thing you can create constants and can directly use them no need to add global thing.

Thanks,
Mukesh Yadav
0
 
Mukesh YadavFull Stack DeveloperCommented:
@Marco a blank space in object method calling syntax can't be an issue.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
hidrauAuthor Commented:
Hello Marco,

There was blank space in that line and now I delete the blank space and I haven't got success yet. You told me to set error, how should I do?

Thanks
0
 
hidrauAuthor Commented:
Hello Mukesh,

I also fixed the lines and nothing:

here is the link:

http://www.teachmenow.com.br/nusoap/client.php
0
 
Ray PaseurCommented:
+1 for Marco's comment about error_reporting(E_ALL) -- always use the highest possible error_reporting() setting.  If you don't want to see the errors in the PHP output, you still have the option of using an error_log file.

The blank space in the method call is probably not the cause of the error.  But this problem is an object lesson in why we choose RESTful interfaces instead of SOAP.  With REST you can see the server-side script as it runs.  With SOAP there may be some guessing!

Here are some things to try in the client script.

  • Add var_dump($client) after line 7
  • Add var_dump($response) after line 9

Here are some things to try in the server script.

  • Add var_dump($server) after line 14
  • Add var_dump($HTTP_RAW_POST_DATA) after line 2
  • Inject $servername, $username, $password, $dbnome  into the function call on line 23
  • Change the order of these statements on line 26: $result = $conn->query($sql); $sql    = "SELECT * FROM CADDOWNLOAD";

Some references you may want to read:
http://php.net/manual/en/function.error-reporting.php
http://php.net/manual/en/reserved.variables.httprawpostdata.php (you probably don't want this)
http://php.net/manual/en/language.variables.scope.php

Good learning resources for those new to PHP:
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
0
 
Marco GasiFreelancerCommented:
Even if my collegues have corrected me (the blank space can't be the cause of the error), you should anyway set error_reporting to E_ALL. It's quite simple: just put these lines at the very top of your php scripts:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');

Open in new window

1
 
hidrauAuthor Commented:
0
 
Ray PaseurCommented:
Great!  Are these the things you expected to find in the var_dump() output?  If not, which ones are unexpected values?
0
 
hidrauAuthor Commented:
I don't see the register that I can see and it should return me as this link :

http://www.teachmenow.com.br/nusoap/testedados.php

Now, I don't know where is the problem, in the serve side or cliente :(
0
 
hidrauAuthor Commented:
Thanks a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now