nuSoap中的数组到字符串转换

时间:2018-05-31 13:51:51

标签: php soap nusoap

我正在尝试使用NuSoap Web服务从我的数据库中获取数据列表。

但是当我执行时,我收到此错误消息:

Notice:  Array to string conversion in C:\wamp64\www\gcm\database.php on line 105
PHP Warning:  mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\wamp64\www\gcm\database.php on line 112

我在网页上测试了下面的功能,我得到了结果(数组表):

数组([0] =>数组([titre] => list des docs [dateHeure] => 2018-04-16 [详情] => hello))

这是我的功能:

function getHistoriqueNotification(){
$com = new DbConnect();
$message=array();
$sql = "select alr_alertes.TITRE,alr_alertes.PHOTO,alr_historiques.DETAIL,alr_historiques.DATEHEURE,alr_alertes.CODE from alr_alertes,alr_historiques WHERE alr_alertes.ALRT_UID=alr_historiques.ALRT_UID" ;
$result = mysqli_query($com->getDb(),$sql);
while($row=mysqli_fetch_assoc($result)){
  $message[] = array(

      'titre'     =>$row['TITRE'], 
      'dateHeure' =>$row['DATEHEURE'],
      'detail'    =>$row['DETAIL'],
      'code'      =>$row['CODE']
    );
}
return ($message);
}

我的Web服务的实现:

<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
 require_once 'config.php';
require_once 'database.php';
// Create the server instance
$server = new soap_server();
$server->configureWSDL('Myservice_wsdl', 'urn:Myservice_wsdl');
$server->soap_defencoding = 'UTF-8';

$server->wsdl->addComplexType('Notifications',
    'complexType',
    'struct',
    'all',
    '',
    array(
            'titre' => array('name' => 'titre', 'type' => 'xsd:string'),
            'dateHeure' => array('name' => 'dateHeure', 'type' => 'xsd:date'),
            'detail' => array('name' => 'detail', 'type' => 'xsd:string'),
            'code' => array('name' => 'code' , 'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType('notificationArray',
    'complexType',
    'array',
    '',
    'SOAP-ENC:Array',
    array(),
    array(
            array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Notifications[]')
    ),
'tns:Notifications'
);
$server->register('getHistoriqueNotification',
                        array(),
                        array('result' =>'tns:notificationArray'),
                          'urn:MyService_wsdl',
                        'urn:MyService_wsdl#getHistoriqueNotification',
                        'rpc',
                        'encoded',
                        'Some comments about function 1'


                      );
 $server->service(file_get_contents("php://input"));

        ?>

1 个答案:

答案 0 :(得分:0)

我认为您的lib DbConnect已损坏。我们可以看到它返回一些不正确的东西:

Notice:  Array to string conversion in C:\wamp64\www\gcm\database.php on line 105

然后mysqli_query在$ sql中获取false而不是mysqli_result