Just look at the generated string:
INSERT INTO 'wp_table' (id, datea, one, two) VALUES (1, '2013-12-24', 3, 'NULL') ON DUPLICATE KEY UPDATE one = VALUES(one), two = VALUES(two);
The problem is the quotes around the table name. (Your hand-written query has no quotes around the table name, and works.) prepare
is intended for dynamic user supplied, content, and it is intended for use with strings and numbers. The table name is neither– not in the same way that your content is. It is going to supply quotes, which is going to break your query.
You should be able to simply write the table name into the query.
$arr = array();
array_push( $arr, 1, '2013-12-24', 3, 'NULL');
$sql_prepare = "INSERT INTO {$wpdb->prefix}table (id, datea, one, two) VALUES (%d, %s, %d, %s) ON DUPLICATE KEY UPDATE one = VALUES(one), two = VALUES(two);";
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
- 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
- PHP variables in mysql query
- 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’
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (38)
- ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
- Getting “Lock wait timeout exceeded; try restarting transaction” even though I’m not using a transaction
- Search for all occurrences of a string in a mysql database
- How to update a record using sequelize for node?
- Can’t open the mysql.plugin table. Please run mysql_upgrade to create it
- Convert partially non-numeric text into number in MySQL query
- MySql: is it possible to ‘SUM IF’ or to ‘COUNT IF’?
- MySQL Select Multiple VALUES
- MySQL Error #1071 – Specified key was too long; max key length is 767 bytes
- How To have Dynamic SQL in MySQL Stored Procedure
- MySQL – UPDATE query with LIMIT
- What SQL Query to do a simple find and replace
- Can i use php sql functions instead of $wpdb?
- Scanning Database for malicious Data
- Is it useful to turn on MySQL query cache for performance
- Programmatically changing role information; editing role name and deleting
- How to let a user choose an authors and save it to the database?
- How to remove ‘GROUP BY’ from SQL query produced from get_posts?
- WordPress installation on valet php 8 (PHP Fatal error: Uncaught mysqli_sql_exception Table ‘wp_options’ doesn’t exist in wp-includes/wp-db.php:2056)
- MySQL crashed because of the large number of requests
- Why doesn’t this code add a table to my database?
- SQL database export-import
- Convert simple SQL Query to WordPress query
- Uncaught Error: Call to undefined function mysql_connect() – WordPress installation
- SQL Database, repeated tables?
- Visual/Text Editor displays blank pages in WP-Admin- but HTML on client side displays correctly
- Code to remove authors with no posts connected to them
- SQL Query in WordPress – Getting Impossible WHERE error
- WordPress create database not working
- database optimization and server errors
- How to create more than one new wpdb object?
- Calling mysql_query() on another database, assumes WordPress using that database
- querying user bookmarks from a large number of bookmarks
- How do I echo all users’ display_name and their meta_value who have a certain meta_key?
- How to simulate web traffic to test performance of a website
- Remove escape characters from JSON string pulled from a database
- SQL. Select category descendants
- Why is local wordpress install calling live site executions?
- Display MySQL as part of a Page
- Migration of wordpress database from mariadb 10.0.20 to 5.5.50
- Internal error (500) on local & Fatal error on live when trying to access post type edit screen