Jump to content

Double Insert Or Trigger?


stevew

Recommended Posts

I need both id values to mirror each other so I can query them from either table and get the same data. Can I depend on a double INSERT like below or should I set up a trigger?

 

mysql_query("INSERT INTO tb1 (id,value2,value3) VALUES ('$id','$val2','$val3')");

mysql_query("INSERT INTO tb2 (id,value2,value3) VALUES ('$id','$val2','$val3')");

 

 

On a side note, would appreciate some comments regarding what kind of hashing to implement.

 

md5 with salt, sha1 with salt, crypt(), hash()........

 

thx

Link to comment
Share on other sites

Why would you want two tables to contain the exact same content? For me that seems like you're doing something wrong, and it breaks with data normalization. If you tell us what you want to accomplish with it, we can probably suggest a much better alternative.

 

As for the hashing of passwords (I assume), then the best article you can read is this article. If it's not passwords, then we need to know what it is and why you want to hash it.

Edited by Christian F.
Link to comment
Share on other sites

You could just run both queries in a single statement. You could also set up a transaction so if one fails the other is either rolled back or not executed. But, I have to ask, for what purpose are you doing this? If you are doing it as a fail-safe or for scalability it makes no sense.

 

It makes no sense as a fail-safe because whatever you do to table 1 you are going to do to table 2. So, if the data gets corrupted it will be corrupted in both.

 

It makes no sense for scalability because the two tables are in the same database. So, you will not gain any benefits for higher scalability.

 

 

If you want to have a fail safe or increase scalability you need to be looking at having a separate database that is synced up with the primary. However, this is something that is handled in the infrastructure - not the code.

Link to comment
Share on other sites

As for the hashing of passwords (I assume), then the best article you can read is this article. If it's not passwords, then we need to know what it is and why you want to hash it.

 

Yes, I was referring to passwords.

 

 

You could just run both queries in a single statement.

 

Got it thanks.

Edited by stevew
Link to comment
Share on other sites

What is the purpose of this? I'm really not interested in investing my time to help someone accomplish something that, on the face of it, is foolish. If you have a valid reason for doing this I'll be happy to help. Otherwise, I'm not going to assist someone in implementing something that has no value and would be helping to instill poor practices.

Link to comment
Share on other sites

What is the purpose of this? I'm really not interested in investing my time to help someone accomplish something that, on the face of it, is foolish. If you have a valid reason for doing this I'll be happy to help. Otherwise, I'm not going to assist someone in implementing something that has no value and would be helping to instill poor practices.

 

Sorry..it is for a messaging system...after some thought since my last post...instead of duplicating the data for the purpose of allowing users to track sent messages I am now using boolean values in the same table to track when a user has "deleted" a message from their inbox or outbox and display accordingly.

 

Thanks for pointing me in the right redirection.

Edited by stevew
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.