On this page
wpdb::insert( string $table, array $data, array|string $format = null ): int|false
Inserts a row into the table.
Description
Examples:
wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
See also
- wpdb::prepare()
- wpdb::$field_types
- wp_set_wpdb_vars()
Parameters
$tablestring Required-
Table name.
$dataarray Required-
Data to insert (in column => value pairs).
Both $data columns and $data values should be "raw" (neither should be SQL escaped).
Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case. $formatarray|string Optional-
An array of formats to be mapped to each of the value in $data.
If string, that format will be used for all of the values in $data.
A format is one of'%d','%f','%s'(integer, float, string).
If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.Default:
null
Return
int|false The number of rows inserted, or false on error.
Source
File: wp-includes/class-wpdb.php. View all references
public function insert( $table, $data, $format = null ) {
return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' );
}
Related
Uses
| Uses | Description |
|---|---|
| wpdb::_insert_replace_helper() wp-includes/class-wpdb.php | Helper function for insert and replace. |
Used By
| Used By | Description |
|---|---|
| wp_insert_site() wp-includes/ms-site.php | Inserts a new site into the database. |
| add_network_option() wp-includes/option.php | Adds a new network option. |
| populate_network() wp-admin/includes/schema.php | Populate network settings. |
| wp_install_defaults() wp-admin/includes/upgrade.php | Creates the initial content for a newly-installed site. |
| wp_insert_link() wp-admin/includes/bookmark.php | Inserts a link into the database, or updates an existing link. |
| update_usermeta() wp-includes/deprecated.php | Update metadata of user. |
| wp_insert_term() wp-includes/taxonomy.php | Adds a new term to the database. |
| wp_set_object_terms() wp-includes/taxonomy.php | Creates term and taxonomy relationships. |
| wp_insert_user() wp-includes/user.php | Inserts a user into the database. |
| wp_insert_post() wp-includes/post.php | Inserts or update a post. |
| wpmu_log_new_registrations() wp-includes/ms-functions.php | Logs the user email, IP, and registration date of a new site. |
| wpmu_signup_blog() wp-includes/ms-functions.php | Records site signup information for future activation. |
| wpmu_signup_user() wp-includes/ms-functions.php | Records user signup information for future activation. |
| wp_insert_comment() wp-includes/comment.php | Inserts a comment into the database. |
| add_metadata() wp-includes/meta.php | Adds metadata for the specified object. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/insert