Using Saurus database API
You can use database API in your custom PHP scripts for quering the database with the SQL object.The first step is to enable API usage as described on PHP and Saurus CMS page.
Example for simple insert:
new SQL("insert into ext_test_table (date, value) values (now(), 'Hello World!')");
Note that tables not part of the CMS installation are prefixed with 'ext_'.
For quering data:
$result = new SQL("select * from ext_test_table where date > '2000-01-01'");
while($row = $result->fetch('ASSOC'))
{
echo $row['date'].':'.$row['value'];
}
The SQL::fetch(type) method acts like PHP's mysql_fetch_array() function. The methods argument (possible values are: 'ASSOC', 'NUM', 'BOTH') determines if the array is assocative, numeric or both, with both being default.
Other useful methods and members are:
SQL::fetchsingle() - returns only the first value of the result. Example:
$result = new SQL('select count(id) from ext_test_table');
$id_count = $result->fetchsingle();
SQL::field_name(field_number) - returns the name of the specified field in a result.
SQL::rows - the affected rows by the query.
SQL::insert_id - last inserts ID
SQL::error_no - MySQL error number
SQL::error - MySQL error text
