To insert data you should use query()
(documentation), get_var()
method is for selecting data. If error is encountered, query()
returns FALSE.
query()
This function returns an integer value indicating the number of rows affected/selected for SELECT, INSERT, DELETE, UPDATE, etc.
For CREATE, ALTER, TRUNCATE and DROP SQL statements, (which affect whole tables instead of specific rows) this function returns TRUE on success. If a MySQL error is encountered, the function will return FALSE.
$result = $wpdb->query( 'insert query' );
if ( $result === FALSE ) {
// display error
}
Related Posts:
- How do you properly prepare a %LIKE% SQL statement?
- wpdb->prepare function remove single quote for %s in SQL statment
- 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
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- Cannot delete or update a parent row: a foreign key constraint fails
- Cannot delete or update a parent row: a foreign key constraint fails
- Rename a column in MySQL
- Cannot delete or update a parent row: a foreign key constraint fails
- How do I import an SQL file using the command line in MySQL?
- #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’
- What is the definition of cardinality in SQL
- SQL Query Where Field DOES NOT Contain $x
- How to join two tables by multiple columns in SQL?
- mysql Foreign key constraint is incorrectly formed error
- Selecting data from two different tables without using joins
- MySQL: Invalid use of group function
- difference between primary key and unique key
- Simple Random Samples from a Sql database
- What does SQL clause “GROUP BY 1” mean?
- How can I prevent SQL injection in PHP?
- Generating a random & unique 8 character string using MySQL
- SQL select only rows with max value on a column
- Unknown Column In Where Clause
- SQL statement not working – “Operand type clash: date is incompatible with int’
- Repair all tables in one go
- #1062 – Duplicate entry for key ‘PRIMARY’
- ERROR 1115 (42000): Unknown character set: ‘utf8mb4’
- Remove Primary Key in MySQL
- Is merge statement available in MySQL
- Error: Duplicate entry ‘0’ for key ‘PRIMARY’
- How to get the count of each distinct value in a column?
- Optimize WordPress Query that take 5 seconds to execute
- Multipart/formatted MySQL query problem
- “#1067 – Invalid default value for ‘post_date'” when trying to reset AI after backup
- Increment value (value = value+1) of $wpdb->update
- Inserting Post Meta From SQL
- wpdb Custom Meta Data with 2 conditions
- Extending the database
- wpdb prepare syntax
- SQL query not working in alphabetical post title/content search
- 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
- 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()?
- $wpdb->insert() does not Insert record in a table
- WordPress SQL Issue not returning correct reselts
- SQL command to convert all tags in lowercase?
- WordPress(wpdb class) and mysql stored procedures
- Can’t run database query
- How to stop $wpdb from prepending database name
- WordPress $wpdb get posts from category and sort by custom meta
- How can I add a new row in a separate database when someone registers via WordPress?
- Getting Error Trying to Create Table
- How to set MYSQLI_OPT_INT_AND_FLOAT_NATIVE option
- How can I write a formal sql query to get data from a custom table
- 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
- Database SQL query error
- Data is not constatntly loading from custom wordpress table
- 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
- Delete oldest wordpress post (SQL query)
- How to search usermeta table
- How to add virtual column in wpdb get_result statement
- How to show result of sql query in a page?
- update_option returns false in AJAX, how to debug?
- Improving performance of SQL sub-queries in WordPress
- An SQL query to find orphaned image attachments and their meta
- CONCAT_WS in custom sql query
- MySQL Select within WP Page template
- Saving custom term value to the database in new table
- SQL error on restoring database
- optimise SQL wordpress call
- why is $wpdb->update() causing a DB error from within wp_set_password()
- Woocommerce: Grab total revenue of a product over all orders
- Delete posts with word count less than x number of words
- $wpdb->get_var returns 0
- Get all the related data from WordPress DB
- SQL command to export post_content from wp_posts using phpMyAdmin
- SQL get last entry of a specific gravity form
- Is there an equivalent of MySQL’s SHOW CREATE TABLE in Postgres?
- Possible SQL injection. How to locate and fix?