Php 在RESTAPI方法中,如何在不传递任何参数的情况下获得函数结果?

Php 在RESTAPI方法中,如何在不传递任何参数的情况下获得函数结果?,php,function,rest,Php,Function,Rest,我的职能 public static function getArtistCount() { global $DB; $sql = "SELECT COUNT(*) AS Count FROM tbl_artists"; if (!$DB->Query($sql)) { return false; } if (!$rows = $DB->RecordsArray(1)) { return false;

我的职能

public static function getArtistCount()
{
    global $DB;
    $sql =  "SELECT COUNT(*) AS Count FROM tbl_artists";

    if (!$DB->Query($sql)) {
        return false;
    }

    if (!$rows = $DB->RecordsArray(1)) {
        return false;
    }

    $count= $rows[0]['Count'];
        return $count;
    }
我还有一个结果变量来调用rest并存储数据

$result = Utility_API::callREST($params , 'Artist/get')
我的休息服务是免费的

public function get()
{
    $status = false;
    $result = array();

    if ($result = Data_Artist::getArtistCount()) {
        $status = true;
        $data = $result->toArray();
    }

    return $this->generateReturn($status, $data);
}

我需要知道如何获取计数,还需要知道在不需要或未传递任何参数时如何获取函数结果。

不发送任何参数:

如果您的REST服务可以简单地处理它,您可以在
$params
中传递empty。通常,它将是一个数组(同样,取决于API)

正在获取计数:

取决于
$this->generateReturn($status,$data)
的输出,它返回什么?这将在
$result
中捕获

尝试echo
var\u dump($result)
查看您从该调用中得到了什么

同时,尽可能放置echo语句以查看发生了什么,例如:

if ($result = Data_Artist::getArtistCount()) {
        $status = true;
        echo "I am here and the result is :";
        echo var_dump($result);
        $data = $result->toArray();
        echo "This is my data!" . var_dump($result);
    }

祝你好运

我已经尝试过了,但是得到的结果都是空的,因为我手动运行查询,所以我能够在wamp中得到结果。
if ($result = Data_Artist::getArtistCount()) {
        $status = true;
        echo "I am here and the result is :";
        echo var_dump($result);
        $data = $result->toArray();
        echo "This is my data!" . var_dump($result);
    }