by rleyba » Sun Jan 16, 2011 4:17 am
Hi Steve,
Thanks for your example in the post. I did a search of the xataface forums for other trigger examples which I would need for my requirements, but I am getting stuck with the syntax.Can I just ask for help with the syntax of the PHP trigger statements? Basically, I have two tables linked together many-to-many, in exactly the same way that your Courses/Programs tutorial works. The table joining the SERVERS (IJWTF_IP) and SERVER_IP_ADDRESSES table is the
SERVERTOIP table. So every time I link a server to an IP address, an entry gets created in the SERVERTOIP table. I am trying to create a trigger such that every time an entry on this SERVERTOIP table gets created or updated, it would populate the SERVER_IP_ADDRESSES.SERVER_NAME with the Name of the server it is being linked to from the IJWTF_IP(which is the server table).
My syntax is below, I know it is wrong, but I just don´t know how to fix it.
Thanks very much.
<?
class tables_SERVERTOIP {
function beforeSave($record){
$sqlresult = mysql_query"(Update SERVER_IP_ADDRESS
SET SERVERNAME = ("SELECT IJWTF_IP.SERVER_NAME FROM SERVERTOIP, IJWTF_IP WHERE IJWTF_IP.IJWTF_IP_KEY =
SERVERTOIP.SERVER_ID and SERVERTOIP.IP_ID = '$IP_ID'")");
$record->setValue('IJWTF_IP.SERVER_NAME',$sqlresult);
}
}
?>
------------------Table schema-------------------
CREATE TABLE IF NOT EXISTS `SERVERTOIP` (
`SERVER_ID` int(11) NOT NULL,
`IP_ID` int(11) NOT NULL,
PRIMARY KEY (`SERVER_ID`,`IP_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `IJWTF_IP` (
`IJWTF_IP_KEY` int(11) NOT NULL auto_increment COMMENT 'Primary Key',
`SERVER_NAME` varchar(20) default NULL,
`OS_NAME` varchar(10) NOT NULL,
`SERVER_ID` char(12) NOT NULL,
`COMMENTS` varchar(255) NOT NULL,
PRIMARY KEY (`IJWTF_IP_KEY`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `SERVER_IP_ADDRESS` (
`IP_ID` int(11) NOT NULL auto_increment,
`IP_ADDRESS` char(15) NOT NULL,
`MAC` char(17) NOT NULL COMMENT 'MAC Address',
`NETMASK` char(17) NOT NULL,
`SERVER_NAME` varchar(20) default NULL COMMENT 'Populated by a trigger',
PRIMARY KEY (`IP_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;