Solved

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

Posted on 2016-08-10
11
57 Views
Last Modified: 2016-09-25
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
Comment
Question by:hidrau
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 6

Expert Comment

by:Mukesh Yadav
Comment Utility
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
 
LVL 6

Expert Comment

by:Mukesh Yadav
Comment Utility
@Marco a blank space in object method calling syntax can't be an issue.
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
Hello Mukesh,

I also fixed the lines and nothing:

here is the link:

http://www.teachmenow.com.br/nusoap/client.php
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
Comment Utility
+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
 
LVL 30

Assisted Solution

by:Marco Gasi
Marco Gasi earned 250 total points
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Great!  Are these the things you expected to find in the var_dump() output?  If not, which ones are unexpected values?
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 1

Author Closing Comment

by:hidrau
Comment Utility
Thanks a lot.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now