[Phpmyadmin-devel] [Create PHP Code] creates unexpected results when defining a trigger in SQL window ?
Bill Hernandez
ms at mac-specialist.com
Fri Jul 31 02:37:25 CEST 2009
Thanks very much for the previous help...
Basking in the SUN of my new found happiness, now that I have a non-
crashing and fully functional Firefox/phpMyAdmin DUO, after sadly
parting from a long friendship with Safari...
I created a table via the phpMyAdmin GUI (NOT using the SQL window),
with the following structure.
------------------------------------------------------
CREATE TABLE `mvc_project_01`.`telephones` (
`id` INT NOT NULL AUTO_INCREMENT,
`fk_users_id` INT NOT NULL COMMENT 'Users Foreign Key',
`location` VARCHAR(30) NOT NULL,
`country_code` VARCHAR(4) NOT NULL,
`area` VARCHAR(5) NOT NULL,
`number` VARCHAR(8) NOT NULL,
`created` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' on
update CURRENT_TIMESTAMP,
`modified_by` VARCHAR(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
------------------------------------------------------
after saving the table, I clicked on [Create PHP Code] button, and it
generated the correct php :
------------------------------------------------------
$sql = "CREATE TABLE `mvc_project_01`.`telephones` (`id` INT NOT NULL
AUTO_INCREMENT, `fk_users_id` INT NOT NULL COMMENT \'Users Foreign Key
\', `location` VARCHAR(30) NOT NULL, `country_code` VARCHAR(4) NOT
NULL, `area` VARCHAR(5) NOT NULL, `number` VARCHAR(8) NOT NULL,
`created` TIMESTAMP NOT NULL DEFAULT \'0000-00-00 00:00:00\',
`modified` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT
\'0000-00-00 00:00:00\', `modified_by` VARCHAR(30) NOT NULL, PRIMARY
KEY (`id`)) ENGINE = InnoDB;";
------------------------------------------------------
I copied the text to BBEdit,and replaced every ',', with ',\n', and
made a couple of other minor adjustments, which makes the php easier
to read :
------------------------------------------------------
$sql = "
CREATE TABLE `mvc_project_01`.`telephones` (
`id` INT NOT NULL AUTO_INCREMENT,
`fk_users_id` INT NOT NULL COMMENT \'Users Foreign Key\',
`location` VARCHAR(30) NOT NULL,
`country_code` VARCHAR(4) NOT NULL,
`area` VARCHAR(5) NOT NULL,
`number` VARCHAR(8) NOT NULL,
`created` TIMESTAMP NOT NULL DEFAULT \'0000-00-00 00:00:00\',
`modified` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT
\'0000-00-00 00:00:00\',
`modified_by` VARCHAR(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
";
------------------------------------------------------
I didn't know how to add the trigger via the phpMyAdmin GUI, so I
decided to use the SQL window.
I put the following Trigger Definition in the SQL window, after
creating the table :
------------------------------------------------------
DROP TRIGGER IF EXISTS `mvc_project_01`.`telephones_insert_trigger`;
DELIMITER ;;
CREATE TRIGGER `mvc_project_01`.`telephones_insert_trigger` BEFORE
INSERT ON `mvc_project_01`.`telephones`
FOR EACH ROW BEGIN
SET NEW.created = NOW();
SET NEW.modified = NOW();
END;
;;
DELIMITER ;
------------------------------------------------------
Everything went well, phpMyDamin was happy, but when I clicked on
[Create PHP Code] the result below was not what I had expected :
------------------------------------------------------
$sql = "# MySQL returned an empty result set (i.e. zero rows).\n"
. "\n"
. "DELIMITER ;\n"
. "";
------------------------------------------------------
Any Ideas what I might be doing wrong ?
Thank You Very Much...
Bill Hernandez
Plano, Texas
More information about the Developers
mailing list