0

i'm a little bit new in WordPress and for now working on WordPress site that some information will insert to database from forms ... i design some page template and use mysqli_connect() to connect database and mysqli_query() to insert data to database .

the question i wonder is , am i do mistake ? is it possible that pages or piece of database erase after WordPress updates or totaly Could something bad happen? should change anything or not ?

i will thanks to anyone that help me. :)

3
  • If you do it right, nothing will break. But wordpress has a lot of build-in functions to CRUD posts, meta, terms, users and so on. For very complex solutions there is wpdb class for working with wp database. Why you desided to use mysqli_connect() instead?
    – anton
    May 2, 2021 at 7:08
  • because for that time i not familiar with wpdb class ...
    – hossein
    May 2, 2021 at 9:03
  • then i sure about my template pages that nenver will delete because of updates and etc ?
    – hossein
    May 2, 2021 at 9:17

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.