2
The core takes care of initializing the database (connecting to the server and selecting the database), so the module doesn't need to do anything in that regard.
The methods for accessing the database are in class/database/mysqldatabase.php.
Here are some examples:
$table = $xoopsDB->prefix('chess_pending_games');
$xoopsDB->query("INSERT INTO $table
SET
game_type = '$gametype',
color_option = '$coloroption'
");
if ($xoopsDB->errno()) {
trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR);
}
$table = $xoopsDB->prefix('chess_pending_games');
$xoopsDB->query("DELETE FROM $table WHERE pending_game_id='$pending_game_id'");
if ($xoopsDB->errno()) {
trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR);
}
$pending_games_table = $xoopsDB->prefix('chess_pending_games');
$result = $xoopsDB->query("SELECT game_type, color_option
FROM $pending_games_table
WHERE pending_game_id = '$pending_game_id'
");
if ($xoopsDB->getRowsNum($result) < 1) {
redirect_header(XOOPS_URL.'/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND);
}
$row = $xoopsDB->fetchArray($result);
$xoopsDB->freeRecordSet($result);
The trigger_error() calls are for debugging; I may handle that differently in the final code.