To insert a new row:
global $wpdb;
$wpdb->insert(
'wp_mytable',
array( 'product' => $product ),
array( '%s' )
);
For the sake of completeness, $wpdb->update
is used to update an existing row and requires an additional WHERE clause, as would a “regular” SQL query. For example:
global $wpdb;
$wpdb->update(
'wp_mytable',
array( 'product' => $product ),
array( 'product_id' => 1312 ),
array( '%s' ),
array( '%d' )
);
Related Posts:
- How do you properly prepare a %LIKE% SQL statement?
- $wpdb and MySQL Create Trigger
- wpdb->prepare function remove single quote for %s in SQL statment
- Alternative to mysql_real_escape_string
- Increment value (value = value+1) of $wpdb->update
- wpdb Custom Meta Data with 2 conditions
- wpdb prepare syntax
- SQL query not working in alphabetical post title/content search
- MySQL LIKE not working
- Proper way to work with wpdb to get user’s firstname
- How to check for empty and not a failure
- Database: Custom table: sprintf value for DateTime column
- Converting mysql to $wpdb
- WP_USE_EXT_MYSQL
- wpdb insert and boolean fields
- Join new table with SQL query
- writing inner join in wpdb
- How to split the a table in database?
- MySQL Rank & $wpdb
- When WordPress Default table, Echo Success. When Plugin Table, Echo Blank
- How do I join a $wpdb query with user meta using default value if not exist?
- How to translate this mySQL query to $wpdb query
- $wpdb select all meta for each post
- $wpdb to insert html form information
- Proper usage of $wpdb->update()?
- WordPress(wpdb class) and mysql stored procedures
- Can’t run database query
- Using WPDB->Insert()
- Active DB queries in WordPress?
- How to stop $wpdb from prepending database name
- WordPress $wpdb get posts from category and sort by custom meta
- How to get INSERT errors from $wpdb?
- Getting Error Trying to Create Table
- How to set MYSQLI_OPT_INT_AND_FLOAT_NATIVE option
- Understanding custom php that reads from WP MYSQL
- How to insert dash (-) into database using wpdb and new_to_publish hook?
- $wpdb->get_var multiple queries in one database check
- List users with the most posts in the last 30 days
- Insert two row in wordpress database
- WordPress $wpdb no result
- MySQL ‘duplicate entry’ error
- User set date and time from frontend doesn’t get stored into database
- Wpdb query with dynamic table name
- get posts whether meta_key exists or not
- when using $wpdb sudden connection rejection without changing anything. Access denied, with errors from repair tool
- How to search usermeta table
- How to add virtual column in wpdb get_result statement
- wpdb insert into point column in db
- WPDB delivers wrong results from complex queries
- $wpdb post type and term query only works when there are no dashes or spaces in the term slug and title
- CONCAT_WS in custom sql query
- Geographical proximity query using post_meta
- MySQL Select within WP Page template
- Saving custom term value to the database in new table
- why is $wpdb->update() causing a DB error from within wp_set_password()
- $wpdb->get_var returns 0
- Initialization of table in database using ‘CREATE … IF NOT EXISTS’
- Not unique table/alias
- Install mysql-python (Windows)
- Disable ONLY_FULL_GROUP_BY
- MySQL WHERE IN ()
- MySQL Error #1133 – Can’t find any matching row in the user table
- How can I prevent SQL injection in PHP?
- Best way to store an array in MySQL database?
- How to grant remote access permissions to mysql server for user?
- #1062 – Duplicate entry for key ‘PRIMARY’
- How can I convert a string to a float in mysql?
- Is there a Profiler equivalent for MySql?
- How to use greater than operator with date?
- How to return number of found rows from SELECT query
- How to replace the domain name in a WordPress database?
- How can I debug my database connection for unit testing?
- Get multiple custom field values in a $wpdb query [duplicate]
- How to get a Google maps SQL->XML->map marker tutorial to work in WordPress
- Update a WordPress post or page takes 60+ seconds
- WordPress get pagination on wpdb get_results
- Modify MySQL Query Based on Dropdown Menu
- Database query works fine outside WordPress
- Alter wp_post table vs. post_meta performance/speed
- Query most popular terms by taxonomy over 2 week period
- $wpdb->prepare with LIKE and sprintf
- SQL syntax error when getting data for a url
- Import CSV to MySQL, with custom registration field information
- Update Custom Post Type Taxonomies with SQL
- Query Column of Specific ID from Database Table
- SQL statement using placeholder is not returning results
- Passing in MySQL prepare statement parameter separately throwing error
- Database SQL query error
- How to Bulk find and replace MySQL for post image url
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- update multiple rows in mysqli table base on two values
- Not getting ajax success response on insert/update row to database
- How can I verify WordPress nonce from the following code?
- How to write in MySQL more characters in user_nicename
- What is the cron doing?
- SQL error on restoring database
- MySQL database gives blank page (white screen of death)
- Datatabase error: Commands out of sync
- Global MySQL replacing of text patterns/matches
- Where other than wp-config can database access details be defined?