lampstax Posted February 2, 2010 Share Posted February 2, 2010 Is it possible to create something in MySQL ( trigger ? stored procedure ? something else ? ) so that when any table is created on a DB thats has a name fitting a certain structure .. lets say like "user1_data", "user2_data" .. to insert a row into that newly created table? Ofcourse this structure is a pretty ugly db design ( not mine ) and it could be done easily a php / java / ruby script, the situation dictates that no script is used. I'm stumped. What about you guys? Quote Link to comment https://forums.phpfreaks.com/topic/190715-is-it-possible-to-do-this-in-mysql/ Share on other sites More sharing options...
lampstax Posted February 2, 2010 Author Share Posted February 2, 2010 Actually if I can get this trigger to work, it would solve my problems too, but I'm have some syntax issues DELIMITER | CREATE TRIGGER wpmu_new_blog_set_default_options AFTER INSERT ON wp_blogs FOR EACH ROW BEGIN SELECT SLEEP(2); SET @var := CONCAT('wp_', NEW.blog_id ,'_options'); UPDATE @var SET option_value = '0' WHERE option_name = 'option_x'; END; | DELIMITER ; I feel like I'm sooo close, but its not working. I"m not too familiar with triggers. I bet its something small that I'm not seeing. The MySQL error that I see is : ERROR 1064 (42000): 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 '@var SET option_value = '0' WHERE option_name = 'option_x'; Quote Link to comment https://forums.phpfreaks.com/topic/190715-is-it-possible-to-do-this-in-mysql/#findComment-1005778 Share on other sites More sharing options...
gizmola Posted February 2, 2010 Share Posted February 2, 2010 You've hit a dead end. MySQL won't allow you to inject dynamic SQL statements into triggers or stored procedures. Quote Link to comment https://forums.phpfreaks.com/topic/190715-is-it-possible-to-do-this-in-mysql/#findComment-1005780 Share on other sites More sharing options...
gizmola Posted February 2, 2010 Share Posted February 2, 2010 Well it looks like this might be doable using a prepared statement, although i'm still not sure it would work in a trigger. Give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/190715-is-it-possible-to-do-this-in-mysql/#findComment-1005787 Share on other sites More sharing options...
lampstax Posted February 3, 2010 Author Share Posted February 3, 2010 Tried it too ways: DELIMITER | CREATE TRIGGER set_default_options AFTER INSERT ON authors FOR EACH ROW BEGIN SELECT SLEEP(2); PREPARE stmt_name FROM "UPDATE authors SET issued = '9' WHERE authorID = ?"; SET @test_parm = "2"; EXECUTE stmt_name USING @test_parm; END; | DELIMITER ; and even this didnt work DELIMITER | CREATE TRIGGER set_default_options AFTER INSERT ON authors FOR EACH ROW BEGIN SELECT SLEEP(2); PREPARE stmt_name FROM "UPDATE authors SET issued = '9' WHERE authorID = '2'"; EXECUTE stmt_name; END; | DELIMITER ; Quote Link to comment https://forums.phpfreaks.com/topic/190715-is-it-possible-to-do-this-in-mysql/#findComment-1006293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.