is it right choose to connect database in template page directly in WordPress site?

If you make data manipulations with mysqli_connect() right, according to database structure etc, it will not break your site. But it’s more safe and logical to use build-in functions to manipulate database data. (Some standarts exists). WordPress has a lot of functions, which allows you to manipulate each wp table’s data. Here are some simple functions as an example:

Posts, pages, CPT
Insert or update post – wp_insert_post()
Update post – wp_update_post()
Trash or delete post – wp_delete_post()
Post meta
Add post meta – add_post_meta()
Update post meta – update_post_meta()
Delete post meta – delete_post_meta()
Taxonomy terms
Insert term – wp_insert_term()
Update term – wp_update_term()
Delete term – wp_delete_term()
Terms meta
Add term meta – add_term_meta()
Update term meta – update_term_meta()
Delete term meta – delete_term_meta()
Options
Add option – add_option()
Update option – update_option()
Delete option – delete_option()

If you working with custom database tables, check wpdb class, which allows you to manipulate with database safely, and you don’t need to worry about connections etc. Each link from wordpress codex, where are a lot of simple examples you can use, the same sql queries if you use wpdb.