You can use Joomla's API directly in your Code action PHP. You don't need to manually establish database connections to Joomla. You can also use CBs API as well. Below is an example of running a query with CBs API.
Code:
global $_CB_database;
$password = sha1( '[password]' );
$query = "UPDATE " . $_CB_database->NameQuote( '#__mytable' )
. " SET " . $_CB_database->NameQuote( 'password' ) . " = " . $_CB_database->Quote( $password )
. " WHERE " . $_CB_database->NameQuote( 'user' ) . " = " . $user->getInt( 'id', 0 );
try {
$_CB_database->setQuery( $query );
$_CB_database->query();
} catch ( RuntimeException $e ) {
// Error Handling Here
}
That's all there is to it. Your query will run using Joomla database connection as our API just calls Joomla's own API. If using Joomla API keep in mind this is inline PHP you can't specify "use" statements (unless you opt to just include a php file) so you need to use the full PHP namespace path.