Can't access mySQL implementing nuSOAP?

This is an UPDATE on my progress, still getting a sympathetic error:

So basically I am not getting return data from my nuSOAP web service when calling a function using mySQLi query

I think due to nuSOAP (there is no evidence yet), anyway, here is the code with nuSOAP in it:

<?php // include the SOAP classes require_once('nuSOAP/lib/nusoap.php'); $host = 'mysql13.000webhost.com'; $user = 'a8434864_updater'; // MySQL login username $pass = '***'; // MySQL login password $database = 'a8434864_lokiupd'; // Database name $con=mysqli_connect($host,$user,$pass,$database); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } function OnlineStatus(){ return true; } function GetRegTitle(){ global $con; $SQL = "SELECT app_reg_title FROM a8434864_lokiupd._misc WHERE id = 0"; $result = mysqli_query($con,$SQL); // ERROR LINE 26 if(!$result) { die(mysqli_error($con)); // ERROR LINE 28 } $row = mysqli_fetch_row($result); return $row[0]; } mysqli_close($con); // create the server object $server = new nusoap_server(); // Initialize WSDL support $server->configureWSDL('userdatawsdl', 'urn:userdatawsdl'); $server->register('OnlineStatus', array(), array('result' => 'xsd:boolean')); $server->register('GetRegTitle', array(), array('result' => 'xsd:string')); if (isset($error)) { $fault = $server->fault('soap:Server','',$error); } // send the result as a SOAP response over HTTP $HTTP_RAW_POST_DATA $post = file_get_contents('php://input'); $server->service($post); ?> 

On the client side (the client that I am not using for me is the SOA Client plugin for firefox), this is the error I get:

PHP error message

Warning : mysqli_query (): Failed to get mysqli in /home/a8434864/public_html/webservice/webservice.php online 26

PHP error message

Warning : mysqli_error () [function.mysqli-error]: could not get mysqli in /home/a8434864/public_html/webservice/webservice.php online 28

However, this code works flawlessly (it is the same as above, but without nuSOAP):

 <?php $host = 'mysql13.000webhost.com'; // Host name Normally 'LocalHost' $user = 'a8434864_updater'; // MySQL login username $pass = '***'; // MySQL login password $database = 'a8434864_lokiupd'; // Database name $con=mysqli_connect($host,$user,$pass,$database); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } function OnlineStatus(){ return true; } function GetRegTitle(){ global $con; $SQL = "SELECT app_reg_title FROM _misc WHERE id = 0"; $result = mysqli_query($con,$SQL); if(!$result) { die(mysqli_error($con)); // TODO: better error handling } $row = mysqli_fetch_row($result); return $row[0]; } echo '1:<br>'; print_r(OnlineStatus()); echo '<br>2:<br>'; print_r(GetRegTitle()); mysqli_close($con); ?> 

What can anyone help me?

+4
source share
2 answers

Fixed. You should close the mysql connection only after you have registered the SOAP functions.

Same:

 $server->register('OnlineStatus', array(), array('result' => 'xsd:boolean')); $server->register('GetRegTitle', array(), array('result' => 'xsd:string')); mysqli_close($con); 

What I did before:

 mysqli_close($con); $server->register('OnlineStatus', array(), array('result' => 'xsd:boolean')); $server->register('GetRegTitle', array(), array('result' => 'xsd:string')); 

Hope this helps someone if they get stuck :)

+1
source

mysql_query() accepts an optional link identifier as an option;

 resource mysql_query ( string $query [, resource $link_identifier = NULL ] ) 

If the link identifier is not passed (but you donโ€™t), it will try to "guess" your connection;

If no link identifier is specified, the last link assumed by mysql_connect () is assumed. If such a link is not found, it will try to create one as if mysql_connect () was called without arguments.

In other words, in the last example, an error message means that it cannot find your connection and is implicitly trying to open a new one for it. I suspect this is due to the callback system used by nuSOAP calling your methods, in contrast to the fact that you call them directly in the previous example.

+2
source

Source: https://habr.com/ru/post/1495391/


All Articles