Complete the code to get the WordPress database global object.
<?php global [1]; ?>The global variable $wpdb is used to interact with the WordPress database.
Complete the code to create a new table name with the WordPress prefix.
$table_name = [1] . 'my_plugin_table';
The $wpdb->prefix property holds the WordPress table prefix, which is used to create custom plugin tables.
Fix the error in the SQL query to create a table with the correct charset collate.
$charset_collate = [1]; $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, PRIMARY KEY (id) ) $charset_collate;";
The correct way to set charset and collation is to concatenate $wpdb->charset with ' COLLATE ' and $wpdb->collate.
Fill both blanks to prepare and execute a safe SQL query to insert data into the plugin table.
$wpdb->[1]( $table_name, array('name' => $name), array([2] => '%s') );
Use insert method to add data and format to specify data types for safe queries.
Fill all three blanks to safely prepare and run a SQL query to get rows where name matches a variable.
$prepared_query = $wpdb->[1]( "SELECT * FROM $table_name WHERE name = [2]", [3] ); $results = $wpdb->get_results($prepared_query);
Use prepare to safely insert variables into SQL. Use '%s' as placeholder for strings and pass the variable $name.