Can i use php sql functions instead of $wpdb?

There are a few different reasons. 1. Separation of Concerns Fundamentally, your logical code (i.e. your plugin or your theme) should not need to know anything about the database. At all. Really. The $wpdb object is the global database access layer, and you should be using it for all of your database access. If you … Read more

$wpdb->insert_id

There is no other way, but I can not see how you need any other way then this. I believe that the insert ID accessed by $wpdb is the last ID by this instance of WPDB, other inserts should not affect that but I’m not sure. <?php $wpdb->insert(“QUERY”); $this_insert = $wpdb->insert_id; ?>

Differences between wpdb->get_results() and wpdb->query()

The difference, if you want to call it that, is that the query() is the most generalized method to do queries with $wpdb, the get_results() method on the other hand is a specific method, which does make use of the query() method to retrieve the specific results of this method and then does some work … Read more

wpdb->insert multiple record at once

$wpdb->query(“INSERT INTO settings-table (option_name, option_value, option_created, option_edit, option_user) VALUES (‘name-1’, ‘val-1’, current_time(‘mysql’), current_time(‘mysql’), ‘user-1’), (‘name-2’, ‘val-2’, current_time(‘mysql’), current_time(‘mysql’), ‘user-2’), (‘name-3’, ‘val-3’, current_time(‘mysql’), current_time(‘mysql’), ‘user-3′)”) In the query which you had posted, the column names shouldn’t be in string.

dbDelta only creates the last table

Run dbDelta for each SQL statement seperately: function myplugin_install(){ global $wpdb; $table_name = $wpdb->prefix . “vehicles”; require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’); $sql = “CREATE TABLE IF NOT EXISTS $table_name ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, description VARCHAR(25) NOT NULL, PRIMARY KEY (id) ); “; dbDelta($sql); $sql2 = “CREATE TABLE IF NOT EXISTS $table_name1 ( … )”; … Read more

WPDB prepare – like % – placeholders?

Yes, they’re normal. They were added in 4.8.3 to fix an SQL injection vulnerability. You can read an article describing the technical reasons for this happening here and the ticket for the change here. The placeholder characters are replaced by the random characters on the last line of $wpdb->prepare() with the $wpdb->add_placeholder_escape() function, which calls … Read more

$wpdb->insert not working in any way

When $wpdb method doesn’t perform as it should it is likely issue with resulting SQL query (because of wrong input or something else). Follow wpdb reference in Codex for troubleshooting: enable database error display via $wpdb->show_errors() check what query is being formed and run via $wpdb->last_query

How to use $wpdb to delete in a custom table

The best WP API solution for this goal is to use the delete() function to remove a row. A small example, to delete the raw ‘ID’ in the custom table ‘eLearning_progress.’ $id = 0815; $table=”eLearning_progress”; $wpdb->delete( $table, array( ‘id’ => $id ) ); But I can’t see which raw you will delete in your table … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)