You can execute the select statement to query data in tables.

Note For more information about the select statement, see Query data.

Prerequisites

Parameters

Parameter Description
query The SQL statement. Configure the parameter based on the required feature.

Examples

The following code provides an example on how to execute the SELECT `PK0`, `boolean`, `long`, `geo` FROM `tableName` LIMIT 10; statement to query data in the table named tableName and specify that a maximum of 10 rows can be returned: The system returns the request type, the schema of the returned results, and the returned results of the query statement.

$request = array(
    'query' => 'SELECT `PK0`, `boolean`, `long`, `geo` FROM `tableName` LIMIT 10;',
);
$response = $this->otsClient->sqlQuery($request);
$sqlRows = $response['sql_rows'];

// print all data metrix
$lines = '';
for ($i = 0; $i < $sqlRows->rowCount; $i++) {
    $line = '';
    for ($j = 0; $j < $sqlRows->columnCount; $j++) {
        $line = $line . (is_null($sqlRows->get($j, $i)) ? "null" : $sqlRows->get($j, $i)) . "\t";
    }
    $lines = $lines . $line . "\n";
}
print $lines;
$sqlRows = $response['sql_rows'];