使用wpdb-> prepare时,MySQL查询不起作用

时间:2017-04-13 11:45:49

标签: php mysql wordpress oop

我需要同时插入两个表,所以我使用$wpdb->query()$wpdb->prepare()在查询中使用BEGIN和COMMIT但不幸的是它不起作用

按[die( $wpdb->last_error );]进行测试,

生成[ WordPress database 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 'INSERT INTO TABLE_NAME ( name ) VALUES ( 'xxxxxx' ); at line 2] ]

P.S。我复制了打印的查询并将其粘贴到mySQL查询窗口和IT WORKS !!!

$wpdb->query( $wpdb->prepare(
       "BEGIN;
       INSERT INTO {$tbl_accounts} ( name ) 
           VALUES ( %s );
       SELECT LAST_INSERT_ID() INTO @last_seller_id;
       INSERT INTO {$tbl_apps} ( seller_id, slug, name, token ) 
           VALUES ( @last_seller_id, %s, %s, %s );
       COMMIT;",
       $seller_name,
       $app_name_sanitized, 
       $app_name, 
       $token_key ) 
);

0 个答案:

没有答案