Wordpress database $ wpdb and get_option ()

So, I develop plugins that create interaction and delete the database using get_option functions.

Now I have seen several tutorials showing how to use the global $ wpdb method to get values ​​from a database.

What is the difference between them and one is better than the other?

+5
source share
5 answers

Using WordPress helper features (not limited to get_option()) ensures that your plug-in is cutting-edge if a new version of WordPress makes changes that could potentially affect your code.

, .

+2

, , get_option(), get_post_meta() . $wpdb. :

$wpdb - , PHP ezSQL . :

1) SQL- $wpdb- > prepare(), $wpdb- > insert() $wpdb- > update(). get_option() - , Key = > Value.

2) $wpdb . : $wpdb- > get_results ($ sql, ARRAY_A) Array , , . $wpdb- > get_results ($ sql) . $wpdb- > get_var ($ sql) ( ). $wpdb- > get_row ($ sql) .

3) $wpdb , , $wpdb- > query ($ sql)

4) WordPress, , $wpdb, , MySQL. ezSQL - .

, , $wpdb WordPress.

get_option() get_post_meta() , get_post_meta() Key = > Value get_option().

, . , . , , . $wpdb.

+3

$wpdb , get_option(), wordpress, . , .

get_option(), , . : add_option, update_option delete_option. .

0

. , . - , . ,

0

.

  • get_option()
  • $wpdb

, (, , ) get_option() . , .

But I develop plugins that manage user data and forms, and in such cases get_option()does not offer the versatility that I need without writing many composite arrays or without tracking several parameters. For multidimensional information or for cross-referencing, related data records for a plugin are $wpdbmuch better - you can structure your own tables and sort / organize as you like.

:)

0
source

All Articles