This is an extension of this question : SO
I want to implement the mysql trigger helpfully provided by @Shadow into a Wordpress plugin. The query=trigger is
$sql_trigger = " drop trigger if exists bi_tbl_B $$ delimiter $$ create trigger bi_tbl_B before insert on tbl_B for each row begin DECLARE v_slug as varchar(255); DECLARE v_url as text; SELECT url, slug INTO v_url, v_slug FROM tbl_A WHERE id = NEW.id; NEW.url=v_url; NEW.slug=v_slug; end; $$ delimiter ; "; mysqli_multi_query($wpdb->dbh,$sql_trigger);
I have few questions:
1) Is this query correct or I need to make changes?
2) Do I have to use any one of this
global $wpdb; or
$mysqli = new mysqli(); $mysqli->connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
3) Is the query safe?