mysql教程触发器数据库教程同步数据方法
function res(){
document.getElementById("tab2").value = "pre_"+document.getElementById("tab1").value;
}
";
`$meta->name`=NEW.$meta->name,
";
`$meta->name`=NEW.$meta->name;
// -----------------------------------------------------------------
$result = mysql_query("select * from $tab1")
or die("Query failed: " . mysql_error());
$i = 1;
if ($i < mysql_num_fields($result)){
$meta = mysql_fetch_field($result);
// -----------------------------------------------------------------
/**
* create trigger `tri_del` BEFORE DELETE on `aaa`
* for each row BEGIN
* DELETE FROM bbb WHERE id =OLD.id;
*/
echo("
");
echo "create trigger " . $tab1 . "_del BEFORE DELETE on $tab1
";
echo "for each row BEGIN
";
echo "DELETE FROM $tab2 WHERE $meta->name =OLD.$meta->name;
";
echo("END;");
}
// -----------------------------------------------------------------
echo("
");
/**
* create trigger `up_date` BEFORE UPDATE on `aaa`
* for each row BEGIN
* UPDATE bbb set a1 = new.a1 , a2=new.a2 where id = new.id;
* END;
*/
$result = mysql_query("select * from $tab1")
or die("Query failed: " . mysql_error());
/**
* get column metadata
*/
$i = 1;
echo "create trigger " . $tab1 . "_update BEFORE UPDATE on $tab1
";
echo "for each row BEGIN
";
echo "UPDATE $tab2 SET
";
while ($i < mysql_num_fields($result)){
$meta = mysql_fetch_field($result);
if (!$meta){
echo "No information available
n";
}
echo "
";
`$meta->name`=NEW.$meta->name,
";
`$meta->name`=NEW.$meta->name