php - 无法访问实现 nuSOAP 的 mySQL?

标签 php mysql web-services nusoap mysql-connect

这是我的进度更新,仍然出现类似错误:

所以基本上我在调用使用 mySQLi 查询的函数时没有从我的 nuSOAP Web 服务中获得返回数据

我认为这是因为 nuSOAP(尚无证据),无论如何这是其中包含 nuSOAP 的代码:

<?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);
?>

从客户端(我使用的客户端不是我制作的,它是用于 firefox 的 SOA 客户端插件)这是我得到的错误:

PHP Error Message

Warning: mysqli_query(): Couldn't fetch mysqli in /home/a8434864/public_html/webservice/webservice.php on line 26

PHP Error Message

Warning: mysqli_error() [function.mysqli-error]: Couldn't fetch mysqli in /home/a8434864/public_html/webservice/webservice.php on line 28



然而,这段代码完美无缺(与上面相同,但没有 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);
?>

发生了什么事有人可以帮助我吗?

最佳答案

mysql_query() 将可选的链接标识符作为选项;

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

如果链接标识符没有传入(而你没有传入),它会尝试“猜测”你的连接;

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



换句话说,在您的后一个示例中,错误消息暗示它找不到您的连接并隐式地尝试为您打开一个新连接。我怀疑这与 nuSOAP 调用您的方法所使用的回调系统有关,而不是您在前面的示例中直接调用它们。

关于php - 无法访问实现 nuSOAP 的 mySQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18066481/

相关文章:

php - symfony2.8 与 php 7.2 中的 session_cache_limiter 错误

java - Android html POST 不工作,没有给出错误

php - 根据 LastModified 列比较两个表?

java - 在 jdbc 连接列表中找不到属性(池名称 ="pool_name_here")值

javascript - NodeJS、mysql 和异步结果

java网络服务: how to identify user

java - Eclipse 中的 WSDL 验证命名空间失败

php - 如何在自定义短代码中获取 WooCommerce 产品对象以避免错误

mysql - mysql 中两个日期时间之间

web-services - 如何记录由 Metro 堆栈发送的 SOAP 消息