我在vtiger webservice中遇到了问题。任何人都可以帮我解决这个问题。我收到此错误"查询失败:对名称"拒绝执行操作的权限在vtiger webservice查询中,我希望通过该查询列出一个模块记录。
我的代码是:
<?php
require_once("../vtlib/Vtiger/Net/Client.php");
require_once("../include/Zend/Json.php");
class CRMwebrequests {
var $endpointUrl;
var $userName;
var $userKey;
var $token;
function __construct($url, $name, $key) {
$this->endpointUrl=$url;
$this->userName=$name;
$this->userKey=$key;
$this->token=0;
}
function getChallenge() {
$httpc = new Vtiger_Net_Client($this->endpointUrl);
$params["operation"]="getchallenge";
$params["username"]=$this->userName;
$response = $httpc->doGet($params);
$httpc->disconnect();
$jsonResponse = Zend_JSON::decode($response);
if($jsonResponse["success"]==false)
die("getChallenge failed:".$jsonResponse["error"]["message"]."<br>");
$challengeToken = $jsonResponse["result"]["token"];
return $challengeToken;
}
function Login() {
$token = $this->getChallenge();
$generatedKey = md5($token.$this->userKey);
$httpc = new Vtiger_Net_Client($this->endpointUrl);
//POST containing array
$response = $httpc->doPost(
array("operation"=>"login", "username"=>$this->userName,
"accessKey"=>$generatedKey));
$httpc->disconnect();
$jsonResponse = Zend_JSON::decode($response);
if($jsonResponse["success"]==false) {
die("Login failed:".$jsonResponse["error"]["message"]."<br>Token:".$token."<br>");
}
$sessionId = $jsonResponse["result"]["sessionName"];
//save session id
$this->token=$sessionId;
//25765819bac6eb068
return true;
}
function Query($query) {
//handle "special" characters
$queryParam = ($query);
$params = array("sessionName"=>$this->token,"operation"=>"query", "query"=>$queryParam);
$httpc = new Vtiger_Net_Client($this->endpointUrl);
$response = $httpc->doGet($params);
$jsonResponse = Zend_JSON::decode($response);
echo "<pre>";
print_r($jsonResponse);
if($jsonResponse["success"]==false) {
die("Query failed:".$jsonResponse["error"]["message"]);
}
//Array of retrieved objects
$retrievedObjects = $jsonResponse["result"];
return $retrievedObjects;
}
function delete($id){
$params = array("sessionName"=>$sessionId, "operation"=>'delete', "id"=>$id);
//delete operation request must be POST request.
$httpc = new Vtiger_Net_Client($this->endpointUrl);
$response = $httpc->doPost($params);
$jsonResponse = Zend_JSON::decode($response);
if($jsonResponse['success']==false){
die('delete failed:'.$jsonResponse['error']['errorMsg']);
}
//Array of retrieved objects
$retrievedObjects = $jsonResponse["result"];
return $retrievedObjects;
}
function LogOut() {
$params = array("operation"=>"logout","sessionName"=>$this->token);
$httpc = new Vtiger_Net_Client($this->endpointUrl);
$response = $httpc->doGet($params);
$jsonResponse = Zend_JSON::decode($response);
if($jsonResponse["success"]==false) {
//handle the failure case.
die("Logout failed:".$jsonResponse["error"]["message"]);
}
return true;
}
}
$CRMurl = 'http://localhost/vtigercrm';
$APPkey = 'R6JNLCLkjCFTm44b';
$crmobject = new CRMwebrequests($CRMurl."/webservice.php", "admin", $APPkey);
if ($crmobject->Login()) {
$wsquery = "SELECT * FROM vtiger_account";
$Details = $crmobject->Query($wsquery);
echo "<b>Accounts</b><br>";
echo "<table border='1'>";
echo "<tr>";
echo "<th>Account No</th>";
echo "<th>Accoun Name</th>";
echo "<th>Account Type</th>";
echo "<th>Industry</th>";
echo "<th>Ownership</th>";
echo "</tr>";
foreach ($Details as $value){
echo "<tr>";
echo "<td>".$value["account_no"]."</td>";
echo "<td>".$value["accountname"]."</td>";
echo "<td>".$value["account_type"]."</td>";
echo "<td>".$value["industry"]."</td>";
echo "<td>".$value["ownership"]."</td>";
echo "</tr>";
}
echo "</table></br>";
}
else {
echo "Error!";
}
?>
答案 0 :(得分:0)
您不应该使用真正的数据库表名称来实现&#34; SQL&#34;查询,但只有模块名称,如:
$query = "SELECT * FROM accounts;";
or
$query = "SELECT * FROM Contacts WHERE lastname='Valiant';";