stevew Posted October 30, 2012 Share Posted October 30, 2012 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 https://forums.phpfreaks.com/topic/270075-double-insert-or-trigger/ Share on other sites More sharing options...
Christian F. Posted October 30, 2012 Share Posted October 30, 2012 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. Link to comment https://forums.phpfreaks.com/topic/270075-double-insert-or-trigger/#findComment-1388739 Share on other sites More sharing options...
Psycho Posted October 30, 2012 Share Posted October 30, 2012 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 https://forums.phpfreaks.com/topic/270075-double-insert-or-trigger/#findComment-1388740 Share on other sites More sharing options...
stevew Posted October 31, 2012 Author Share Posted October 31, 2012 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. Link to comment https://forums.phpfreaks.com/topic/270075-double-insert-or-trigger/#findComment-1389050 Share on other sites More sharing options...
Psycho Posted October 31, 2012 Share Posted October 31, 2012 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 https://forums.phpfreaks.com/topic/270075-double-insert-or-trigger/#findComment-1389051 Share on other sites More sharing options...
stevew Posted October 31, 2012 Author Share Posted October 31, 2012 Its ok nm....I realized what you meant after posting and have updated....two INSERTS executing in the same query is all I needed. Link to comment https://forums.phpfreaks.com/topic/270075-double-insert-or-trigger/#findComment-1389052 Share on other sites More sharing options...
stevew Posted October 31, 2012 Author Share Posted October 31, 2012 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. Link to comment https://forums.phpfreaks.com/topic/270075-double-insert-or-trigger/#findComment-1389088 Share on other sites More sharing options...
Christian F. Posted October 31, 2012 Share Posted October 31, 2012 That's a much better solution, indeed. Glad we could help. Link to comment https://forums.phpfreaks.com/topic/270075-double-insert-or-trigger/#findComment-1389100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.