tags
id, display_name
tagLinks
id, rid, tidTags are simply it's just an auto increment id, and a display name I set.tagLinks references two tables to bring them together. Also with a recurring id.
I made a stored function to make inserting easier.
DELIMITER $$
CREATE FUNCTION `getTagId`(myName varchar(255)) RETURNS int(11)
BEGIN
SET @result = (SELECT id FROM `tags` WHERE `display_name`=myName OR `id`=myName);
If @result IS NULL Then
INSERT INTO `tags` (`display_name`) VALUES (myName);
RETURN last_insert_id();
ELSE
RETURN @result;
END If;
END
Basically it trys to find a current "tag" based on the id or display name. If it does not exist, create it and give me that id.I'm using it so I can insert references cleaner.
So the actual code I see in my program is short and clean:
INSERT INTO `tagLinks` (`rid`, `tid`) VALUES
(1, getTagId('Random Tag Name1')),
(1, getTagId('Random Tag Name2')),
(1, getTagId('Random Tag Name3')),
(1, getTagId('Random Tag Name4'))This works great in mysql workbench, however when implemented on the server I can't run stored procedures or functions. I ask my host and apparently cPanel has a bug where it can't add it "execute". Not sure how I was running it in workbench though. The host said they will fix the cPanel bug in "a week or so". I asked them to try and add the permission since I don't have access but not a response yet.My question is, do you see an alternative to what I am doing? That's just as clean?


Sign In
Create Account



Back to top









