Database Interaction in Wordpress Flashcards

1
Q

Q: What database management system does WordPress use?

A

A: MySQL or MariaDB.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: What is the default table prefix for WordPress tables?

A

A: wp_.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: How many default tables are there in a WordPress installation?

A

A: 12.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: What table stores post content and metadata?

A

A: wp_posts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: What table stores user information?

A

A: wp_users.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: What global object is used for database interaction in WordPress?

A

A: $wpdb.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: How do you access the WordPress database prefix in code?

A

A: $wpdb->prefix.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: How do you retrieve a specific table name with $wpdb?

A

A: Use $wpdb->table_name (e.g., $wpdb->posts).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: What function should you use to prepare SQL queries safely?

A

A: $wpdb->prepare().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: Why is it important to prepare SQL queries?

A

A: To prevent SQL injection vulnerabilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: What method is used to run a SELECT query?

A

A: $wpdb->get_results().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: What method is used to fetch a single row from a query?

A

A: $wpdb->get_row().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: What method is used to fetch a single value from a query?

A

A: $wpdb->get_var().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: What method is used to insert data into a database?

A

A: $wpdb->insert().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q: What method is used to update data in a database?

A

A: $wpdb->update().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q: What method is used to delete data from a database?

A

A: $wpdb->delete().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Q: What method is used to execute a custom SQL query?

A

A: $wpdb->query().

18
Q

Q: What does $wpdb->last_query return?

A

A: The last SQL query executed by $wpdb.

19
Q

Q: What does $wpdb->num_rows return?

A

A: The number of rows returned by the last query.

20
Q

Q: What does $wpdb->insert_id return?

A

A: The ID of the last inserted row.

21
Q

Q: What table stores site settings and options?

A

A: wp_options.

22
Q

Q: What table links posts to their taxonomies?

A

A: wp_term_relationships.

23
Q

Q: What table stores taxonomy terms?

A

A: wp_terms.

24
Q

Q: What table stores term taxonomy data?

A

A: wp_term_taxonomy.

25
Q

Q: What table stores metadata for posts?

A

A: wp_postmeta.

26
Q

Q: What should you always use when including variables in SQL queries?

A

A: $wpdb->prepare().

27
Q

Q: Why should you avoid hardcoding table prefixes?

A

A: To support sites with custom table prefixes and improve portability.

28
Q

Q: What is the purpose of escaping output in database queries?

A

A: To prevent XSS attacks by sanitising output before displaying it.

29
Q

Q: What WordPress function can be used to sanitise user input?

A

A: sanitize_text_field(), esc_sql(), or esc_html().

30
Q

Q: Why is it important to validate input before database operations?

A

A: To ensure the data meets expected formats and prevent security risks.

31
Q

Q: How do you create a custom database table in WordPress?

A

A: Use the dbDelta() function in combination with SQL CREATE TABLE statements.

32
Q

Q: What hook is commonly used to create custom database tables?

A

A: register_activation_hook().

33
Q

Q: What is the purpose of the dbDelta() function?

A

A: To create or update database tables in a WordPress-friendly way.

34
Q

Q: How do you check if a custom table exists in the database?

A

A: Query the INFORMATION_SCHEMA or use $wpdb->get_var().

35
Q

Q: What is a common practice for naming custom tables?

A

A: Prefix them with $wpdb->prefix to avoid conflicts.

36
Q

Q: What function can be used to optimise a WordPress database?

A

A: wp db optimize with WP-CLI or directly via SQL commands.

37
Q

Q: How do you clean up orphaned metadata in WordPress?

A

A: Write a custom query to delete unused entries in wp_postmeta or wp_usermeta.

38
Q

Q: Why is it important to index columns in large tables?

A

A: To improve query performance and reduce load times.

39
Q

Q: What WordPress plugin can be used to monitor database queries?

A

A: Query Monitor.

40
Q

Q: How do you back up a WordPress database programmatically?

A

A: Use mysqldump or a plugin like UpdraftPlus.