A CartoDB client for PHP
Pull request Compare This branch is 12 commits behind Vizzuality:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.mkd
cartodb.class.php
cartodb.config.php
example.php
oauth.php

README.mkd

Introduction

This is a very simple PHP library to make use of the CartoDB API as easy as possible. It does not cover the whole API, just the authentication bit (using OAuth) and running SQL queries. If you want to learn more about the CartoDB API check out the documentation

The library is presented as a single file with very few dependencies to make it as easy as possible to use it.

Requirements

Example use

You'll need to get an API key and secret from http://cartodb.com

Then is pretty simple

<?php
require_once 'cartodb.class.php';

# Create the client using the API key and Secret.
$cartodb =  new CartoDBClient('my_cartodb_key','my_cartodb_secret');

# Check if the key and secret work fine and you are authorized
if(!$cartodb->authorized) {
    echo("There is a problem authenticating, check the key and secret");
    die();
}

# Now we can perform queries straigh away. The second param indicates if you want
# the result to be json_decode (true) or just return the raw json string

$result = $cartodb->runSql("SELECT *,geojson(the_geom) FROM my_table",false);
echo($result);

?>

We are working still on the docs, but basically you can run any SQL supported by PostgreSQL and PostGIS. You can also concatenate the queries with ";" to insert multiple records in one shot for example.