0

我正在尝试使用 Soda API 显示来自 Socrata 的一些数据并收到以下消息

来自服务器的错误“0”:

这是什么意思?

这是我的代码:

 $socrata = new Socrata("https://data.medicare.gov", $app_token);
 $params = array("\$where" => "starts_with(zip, $model->zipcode)");
 $response = $socrata->get("/resource/aeay-dfax.json",$params);
 ?> 
 <?= Html::encode($model->zipcode) ?>

 <h2>Results</h2>

  <?# Create a table for our actual data ?>
  <table border="1">
    <tr>
      <th>Last Name</th>
      <th>First Name</th>
    </tr>
    <?# Print rows ?>
    <?php foreach($response as $row) { ?>
      <tr>
        <td><?= $row["lst_nm"] ?></td>
        <td><?= $row["fst_nm"] ?></td>
      </tr>
    <?php } ?>
  </table>

  <h3>Raw Response</h3>
  <pre><?= var_dump($response) ?></pre>
4

1 回答 1

0

您从 Socrata 收到错误的原因是您的查询与可用数据之间的类型不匹配。该zip列被视为纯文本,因此您还必须在 SoQL 查询中为其提供一个字符串。只需$model->zipcode像这样用转义引号括起来:

$params = array("\$where" => "starts_with(zip, \"$model->zipcode\")");

否则,您将给查询一个整数。如果您不想转义双引号,也可以使用单引号。

于 2015-11-06T04:24:45.520 回答