I am trying to display some data from Socrata using Soda API and got the following message **Error “0” from server:**

夙愿已清 提交于 2019-12-11 22:55:00

问题


I am trying to display some data from Socrata using Soda API and got the following message

Error "0" from server:

What does this mean?

This is my code:

 $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>

回答1:


The reason you are getting an error from Socrata is because of a type mismatch between your query and the available data. The zip column is treated as plain text so you must give it a string in your SoQL query as well. Simply wrap $model->zipcode in escaped quotes like so:

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

Otherwise, you'd be giving the query an integer. You could also use single quotes if you don't want to escape the double quotes.



来源:https://stackoverflow.com/questions/33534172/i-am-trying-to-display-some-data-from-socrata-using-soda-api-and-got-the-followi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!