获得了部分解决方案,但要求VPS运行,因为共享主机对游标的操作有限制。
无论如何
DROP PROCEDURE IF EXISTS `update_all_options`;
DELIMITER //
CREATE PROCEDURE update_all_options(
IN db varchar(255),
IN theoption varchar(255),
IN set_val VARCHAR(255)
)
BEGIN
DECLARE table_val VARCHAR(255);
-- Declare variables used just for cursor and loop control
DECLARE no_more_rows BOOLEAN;
-- Declare the cursor
DECLARE options_cur CURSOR FOR SELECT table_name FROM information_schema.tables WHERE TABLE_SCHEMA = db AND TABLE_NAME LIKE \'wp_%options\';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows = TRUE;
OPEN options_cur;
the_loop: LOOP
FETCH options_cur
INTO table_val;
IF no_more_rows THEN
CLOSE options_cur;
LEAVE the_loop;
END IF;
SET @qry = CONCAT(\'UPDATE \', table_val, \' SET option_value = "\', set_val, \'" WHERE option_name = "\', theoption, \'"\');
PREPARE sqlstatement FROM @qry;
EXECUTE sqlstatement;
DEALLOCATE PREPARE sqlstatement;
END LOOP the_loop;
END //
DELIMITER ;
您可以在sql查询窗口中运行它来创建过程。然后它会一直留在你需要的地方。要使用它,请执行以下操作:
CALL update_all_options(\'wpglobal\', \'blog_public\', \'1\');
将wpglobal数据库中名为blog\\u public的所有选项更改为1。PHP可能会容易得多,嗯?或者说,我的同事提出了上述观点:)