gevensen Posted February 8, 2014 Share Posted February 8, 2014 Is there an easy way to compare the structure ( not data ) to see if 2 tables are identical? Ive used describe but im at the point where i have to loop thru the structure of each table I have a project with mutiple databases and tables and the tables in each db need to be identical I can create identical tables but im having an issue figuring out an easier way to simple compare 2 table structure Quote Link to comment Share on other sites More sharing options...
Barand Posted February 8, 2014 Share Posted February 8, 2014 Create the tables to be identical in the first place CREATE TABLE table2 LIKE table1 Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted February 8, 2014 Solution Share Posted February 8, 2014 assuming that the column order is not important, i would implode the lines from each describe table query into an array, one element per line, then use php's array_diff() on the two arrays. if the resulting array is empty, the two tables contained identical definitions. Quote Link to comment Share on other sites More sharing options...
gevensen Posted February 8, 2014 Author Share Posted February 8, 2014 Ive been working on this project for a few years its 117 tables per DB and about 10 DBs In development ive made changes to some of the tables The script i created a while back was missing an update here and there or i was forgetting Ive fixed that now I need to check the tables the array_diff was good what i did was compare the arrays from describe in both tables if(count(array_diff($a,$b)>'0') was greater than zero there's some kind of difference I don't care what difference at that point i take a sql dump of table b, rename table b in case of failure to xb, recreate table b from the structure of table a, import the sql dump and if all is well delete xb I had seen array_diff before but didnt think about taking a count of the arrays returned, where if it was greater than zero i had a problem just ran it on wamp and that seems to do the trick thanks mac_gyver for the thought Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.