0

我试图通过构建一个简单的应用程序来增加我对 PHP 的了解,该应用程序利用通过 Salesforce API 获得的数据。这是我到目前为止所得到的,主要是通过复制/粘贴和查看示例代码:

<?php

define("USERNAME", "");
define("PASSWORD", "");
define("SECURITY_TOKEN", "");

require_once ('[file-path]/SforceEnterpriseClient.php');

$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("[file-path]/wsdl.jsp.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

$query = "SELECT Id, FirstName, LastName, Phone from Contact";
$response = $mySforceConnection->query($query);

echo "Results of query '$query'<br/><br/>\n";
foreach ($response->records as $record) {
    // Id is on the $record, but other fields are accessed via the fields object
    echo $record->Id . ": " . $record->fields->FirstName . " "
        . $record->fields->LastName . " " . $record->fields->Phone . "<br/>\n";
}

?>

问题是,当我尝试运行此脚本(http://moneythink.org/sf-app.php)时,服务器只返回一条错误消息;不知道为什么会这样。

非常感谢任何和所有的帮助!

4

1 回答 1

0

我实际上能够让这个脚本工作。这是功能代码:

<?php

define("USERNAME", "");
define("PASSWORD", "");
define("SECURITY_TOKEN", "");

require_once ('SforceEnterpriseClient.php');

$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("[path-file]/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

$query = "SELECT Id, Name  FirstName, LastName, University__c from Contact";
$response = $mySforceConnection->query($query);

foreach ($response->records as $record) {
    echo 'ID:' .' '. $record->Id . '<br>';
    echo 'First Name:' .' '. $record->FirstName . "<br>";
    echo 'Last Name:' .' '. $record->LastName . "<br>";
    echo 'University:' .' '. $record->University__c . "<br>";
    echo "<br>\n";
}

echo "Size of records:  ".$response ->size;

?>

作为这个新代码的一部分,我从 Salesforce 创建了一个新的 Enterprise WSDL,并且还从 SforceEnterpriseClient.php 中删除了文件路径(我的脚本在同一目录中)。

于 2013-04-15T05:45:07.690 回答