If you have already "require './global.php';" then you can use MyBB's database functions. When you require global.php MyBB will automatically connect to the database, so you don't need to connect again. The database object is $db, and the most simple method is $db->query("your query");. This method wraps mysql_query. The other common ones are:
$db->fetch_array( query ) -- mysql_fetch_array
$db->num_rows( query ) -- mysql_num_rows
$db->escape_string( string ) -- mysql_real_escape_string
$db->insert_id() -- mysql_insert_id
$db->error() -- mysql_error (note this method will be renamed in MyBB 1.4)
The above are used the same way as their standard PHP functions. You can see the full list of methods defined in inc/db_mysql.php.
In addition to wrapping commonly used standard PHP methods for MySQL, we also have our own "simple" methods for insert, update, select, and delete queries.
$db->simple_select( string $table_name [, string $what_to_select [, string $where [, array $options]]] )
example:
$db->simple_select(TABLE_PREFIX."users", "uid, username, email", "usergroup=4", array("order_by" => "uid", "order_dir" => "desc", "limit_start" => 0, "limit" => 10));
The above is equivalent to:
$db->query("SELECT uid, username, email FROM ".TABLE_PREFIX."users WHERE usergroup=4 ORDER BY uid DESC LIMIT 0, 10");
$db->insert_query( string $table_name, array $information )
example:
$insert = array("uid" => 1, "fid" => 4);
$db->insert_query(TABLE_PREFIX."forumsubscriptions", $insert);
The above is equivalent to:
$db->query("INSERT INTO ".TABLE_PREFIX."forumsubscriptions (uid, fid) VALUES (1, 4)");
$db->update_query( string $table_name, array $information [, string $where [, int $limit]] )
example:
$update = array("usergroup" => 4);
$db->update_query(TABLE_PREFIX."users", $update, "uid=1");
The above is equivalent to:
$db->query("UPDATE ".TABLE_PREFIX."users SET usergroup=4 WHERE uid=1");
[b]$db->delete_query( string $table_name [, string $where [, int $limit]] )[/b]
example:[php]$db->delete_query(TABLE_PREFIX."posts", "uid=2");
The above is equivalent to:
$db->query("DELETE FROM ".TABLE_PREFIX."posts WHERE uid=2");
If you want to execute a query from a custom page, just put the query in the PHP file, and whatever you want to output you make into a variable and then put that in the template.
$query = $db->simple_select(TABLE_PREFIX."users", *", "", array("order_by" => "RAND()", "limit" => 1));
$rand_user = $db->fetch_array($query);
$rand_user_username = $rand_user['username'];
Then in your template you would use:
Random user: {$rand_user_username}
Hope that helps.