Example:
<?php
...
function myfunction() {
// this function will use a global singleton instance of Gladius
global $G;
// perform some operation with the Gladius DB engine
...
// check the error variable
if
($G->errno != _G__SUCCESS) {
trigger_error($G->errstr);
return false;
}
// perform other finalization operations
...
return true;
}
...
?>
Debugging SQL queries
Error messages generated by calls to Gladius::Query() will contain the SQL statement, the
offset and other eventual informations. Analyze them to individuate your error; it is often useful
to re-format the SQL text to help the human eye to recognize eventual syntax errors. Always
read the error message because it tells where the problem is, and you can get more than a
clue in solving it.
For example, we execute the following code:
<?php
// create the $sql variable
$sql = 'DELETE * FROM mytable';
// execute the SQL command
if (!$G->Query($sql))
die($G->errstr);
?>
and get this error:
[GLADIUS DB] SQL syntax error in command DELETE at offset 8
You should not have used the asterisk '*' right after DELETE! The statement
DELETE FROM mytable
will instead give a successful result deleting all rows in table mytable.
Testing
The file gladius-testing.php is provviden for general tests of the Gladius DB engine (you can
easily spot a limitation or a bug through specific tests); this is an example usage of it:
<?php
// properly set the databases' directory (it MUST exist)
$GLADIUS_DB_ROOT = 'databases/';
// it will also include gladius.php
include 'gladius-testing.php';
// read the SQL file in memory
$sql = file_get_contents('test.sql');
// begin testing (automatized)
gladius_test($sql);
?>