hyena
hyena

Reputation: 765

LOCK TABLES in wordpress using $wpdb

am trying to run the following code on wordpress

 $sql ="LOCK TABLES some_table LOW_PRIORITY WRITE;"."\n";
 $sql .=" CALL some_stored_pro('somevalue');"."\n";
 $sql .=" UNLOCK TABLES;"."\n";
 $wpdb->query($sql);

am getting the following error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CALL get_one_us_city('aa'); UNLOCK TABLES' at line 2"

when i modify the query above so that it runs only CALL "some_stored_pro('somevalue');" it works perfectly

my question: can we run LOCK TABLES script using $wpdb object?

Upvotes: 1

Views: 3522

Answers (1)

hek2mgl
hek2mgl

Reputation: 157967

You can only execute 1 query per $wp->query(). Separate the SQL into 3 queries and call them one by one:

$queries = array(
    "LOCK TABLES some_table LOW_PRIORITY WRITE",
    "CALL some_stored_pro('somevalue')",
    "UNLOCK TABLES"
);

foreach($queries as $query) {
    $wpdb->query($query);
}

However, I don't know your reasons to call LOCK TABLES but mostly it isn't required.

Upvotes: 1

Related Questions