gpt4 book ai didi

php - CartoDB - SQL API - 使用 php 发布请求

转载 作者:可可西里 更新时间:2023-11-01 17:35:34 25 4
gpt4 key购买 nike

在我的应用程序中,我想使用我的 php 脚本将少量数据发送到我的 cartodb 表。我想使用 SQL-API .我的应用程序以如下形式解析数据:

https://{account}.cartodb.com/api/v2/sql?q=INSERT INTO test_table (column_name, column_name_2, the_geom) VALUES ('this is a string', 11, ST_SetSRID(ST_Point(-110, 43),4326))&api_key={Your API key}

我尝试了几个函数 http_get、file_get_contents、http_request 但没有将数据传递到我的帐户。当我复制/粘贴 URL 并在浏览器中打开时,添加所有内容。

什么是正确的功能?有这么多不同的... PHP-HTTP-Functions

编辑

使用 this solution 中的代码当我打印出响应时出现此错误:

{"error":["syntax error at end of input"]}

在浏览器中我得到这个:

{"rows":[],"time":0.038,"fields":{},"total_rows":1}

我现在的请求代码:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fullurl);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Get the response and close the channel.
$response = curl_exec($ch);
curl_close($ch);
print($response);

最佳答案

找到结果:使用 CURLOPT_POST => 1 它有效!

$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://".$cartodb_key.".cartodb.com/api/v2/sql",
CURLOPT_USERAGENT => 'Sample cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
api_key => $api_key,
q => "INSERT INTO spot (".implode (", ", array_keys($data)).") VALUES (".implode (", ", $data).")"
)
));
$response = curl_exec($ch);
curl_close($ch);

关于php - CartoDB - SQL API - 使用 php 发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32294989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com