问题
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