gpt4 book ai didi

php xmlrpc 读取

转载 作者:行者123 更新时间:2023-12-04 05:52:59 37 4
gpt4 key购买 nike

我不会从表格中读取行来将主题放在列表中
php脚本

$url_obj='http://'.$host.':8069/xmlrpc/object';
$sock=new xmlrpc_client($url_obj);
$msg=new xmlrpcmsg('execute');
$arrVal=array('user_id', 'name');
$msg->addParam(new xmlrpcval($db, "string"));
$msg->addParam(new xmlrpcval(1, "string"));
$msg->addParam(new xmlrpcval($pwd, "string"));
$msg->addParam(new xmlrpcval("res.partner", "string"));
$msg->addParam(new xmlrpcval("read", "string"));
$msg->addParam(new xmlrpcval(3, "int"));
//$msg->addParam(new xmlrpcval($arrVal, "struct"));
print_r("message msg=");
print_r($msg);
$resp= $sock->send($msg);
$val=$resp->value();
$read=$val->scalarval();
echo $read;

我收到错误 PHP Fatal error: Call to a member function scalarval() on a non-object
message msg=xmlrpcmsg Object
(
[payload] =>
[methodname] => execute
[params] => Array
(
[0] => xmlrpcval Object
(
[me] => Array
(
[string] => database
)

[mytype] => 1
[_php_class] =>
)

[1] => xmlrpcval Object
(
[me] => Array
(
[string] => 1
)

[mytype] => 1
[_php_class] =>
)

[2] => xmlrpcval Object
(
[me] => Array
(
[string] => ******
)

[mytype] => 1
[_php_class] =>
)

[3] => xmlrpcval Object
(
[me] => Array
(
[string] => res.partner
)

[mytype] => 1
[_php_class] =>
)

[4] => xmlrpcval Object
(
[me] => Array
(
[string] => read
)

[mytype] => 1
[_php_class] =>
)

[5] => xmlrpcval Object
(
[me] => Array
(
[int] => 3
)

[mytype] => 1
[_php_class] =>
)

)

[debug] => 0
[content_type] => text/xml
)
PHP Fatal error: Call to a member function scalarval() on a non-object in t./est.php on line 27

PHP fatal error :在第 27 行的 t./est.php 中调用非对象的成员函数 scalarval() !

你能帮助我吗 ?

最佳答案

<?php

include_once("lib/xmlrpc.inc");

class OpenERPXmlrpc {

private $user, $password, $database, $services, $client, $res, $msg, $id;

function __construct($usr, $pass, $db, $server) {

$this->user = $usr;
$this->password = $pass;
$this->database = $db;
$this->services = $server;

$this->client = new xmlrpc_client($this->services.'common');

$this->msg = new xmlrpcmsg('login');
$this->msg->addParam(new xmlrpcval($this->database, "string"));
$this->msg->addParam(new xmlrpcval($this->user, "string"));
$this->msg->addParam(new xmlrpcval($this->password, "string"));

$this->res = &$this->client->send($this->msg);

if(!$this->res->faultCode()){

$this->id = $this->res->value()->scalarval();

}
else {

echo "Unable to login ".$this->res->faultString();
exit;
}
}

function read($post = null) {

$this->client = new xmlrpc_client($this->services.'object');

if(empty($post)) {

$ids_read = array(new xmlrpcval('1', 'int'), new xmlrpcval('2', 'int'));

$key = array(new xmlrpcval('id','integer') , new xmlrpcval('name', 'string'));

$this->msg = new xmlrpcmsg('execute');
$this->msg->addParam(new xmlrpcval($this->database, "string"));
$this->msg->addParam(new xmlrpcval(1, "int"));
$this->msg->addParam(new xmlrpcval($this->password, "string"));
$this->msg->addParam(new xmlrpcval("res.partner","string"));
$this->msg->addParam(new xmlrpcval("read", "string"));
$this->msg->addParam(new xmlrpcval($ids_read, "array"));
$this->msg->addParam(new xmlrpcval($key, "array"));

$this->res = &$this->client->send($this->msg);

if(!$this->res->faultCode()) {

$read_html = '<table width="20%" border="0" cellpadding="4" cellspacing="4" align="center">
<tr>
<th>Id</th>
<th>Name</th>
</tr>
';

$scalval = $this->res->value()->scalarval();

foreach ($scalval as $keys => $values) {

$value = $values->scalarval();

$read_html .= '
<tr>
<td>'.$value['id']->scalarval().'</td>
<td>'.$value['name']->scalarval().'</td>
</tr>
<tr><td colspan="2"></td></tr>
';
}

$read_html .= '
</table>
';

return $read_html;
}
else {
return "Not read recode from partner table <br />".$this->res->faultString();
}
}
}

}

$cnt = new OpenERPXmlrpc('admin', 'a', 'test_6_1', 'http://localhost:8069/xmlrpc/');

echo $cnt->read();

?>

解决了 ;)

关于php xmlrpc 读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9851147/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com