xmlrpc_server_call_method() 与类方法
<?php
require_once ('Connections/adodb_mysql_connection.php');
// 实例化我自己的类
$my_report = new external_report($db_connection);
// 设置 XML-RPC "服务器"
$xmlrpc_server_handler = xmlrpc_server_create();
xmlrpc_server_register_method($xmlrpc_server_handler, "external_method", array(&$my_report, "export"));
// 创建 XML 返回数据
if ($response = xmlrpc_server_call_method($xmlrpc_server_handler, $HTTP_RAW_POST_DATA, null))
{
header('Content-Type: text/xml');
echo $response;
}
// **************** 类定义 ****************
class external_report
{
protected $db_connection;
public function __construct($db_connection_pointer)
{
if (method_exists($db_connection_pointer, "Execute")) $this->db_connection = $db_connection_pointer;
else die("...");
}
public function export($method_name, $params_array)
{
$id_dir = (int)$params_array[0];
$id_usr = (int)$params_array[1]; // 未使用,只是一个示例
// 我们必须在此处添加参数验证代码,而不是在构造函数中(像往常一样)
// 因为参数是直接由 xmlrpc_server_call_method 传递的 (?!!)
$myexport = array();
$dirs_query = "SELECT documento_id FROM tabella_cartelle WHERE cartella_id = ".$id_dir;
$dirs_result = $this->db_connection->Execute($dirs_query) or die("...");
$index = 0;
while(!$dirs_result->EOF)
{
$docs_query = "SELECT codice, titolo FROM tabella_documenti WHERE id_documento = ".$dirs_result->Fields('documento_id');
$docs_result = $this->db_connection->Execute($docs_query) or die("...");
$myexport[$index]['codice'] = $docs_result->Fields('codice');
$myexport[$index]['titolo'] = $docs_result->Fields('titolo');
$index++;
$dirs_result->MoveNext();
}
return $myexport;
}
}
?>