I have an html/javascript page that creates some data which is similar to a graph, its an array of nodes, of different types, with different properties including multiple cross-references between nodes, and also sometimes text, which has to be stored on separate tables because it might be translated to other languages.
A json stringify might look like this:
[{"type":"bid-rama","parent":-1,"child":1,"color":"silver","state":{"bid":[0,0,1],"length":3,"turn":"lho","main":{"s":"a83","h":"kq84","d":"jt52","c":"94"},"rho":{"s":"kj92","h":"j3","d":"q93","c":"qj83"},"lho":{"s":"t7","h":"9765","d":"k87","c":"at76"},"cho":{"s":"q654","h":"at2","d":"a64","c":"k52"}}},{"type":"bid-nodo","parents":[0],"fila":2,"children":{"0":2,"-1":4,"5":6},"options":{"0":"mog","-1":"mop","5":"mor","4":"blue","7":"red"},"texts":{"blue":"texto axu","red":"testo roho"},"state":{"bid":[0,0,1],"turn":"main"}},{"type":"bid-rama","parent":1,"child":3,"color":"green","state":{"bid":[0,0,1,0],"length":0,"turn":"lho"}},{"type":"bid-nodo","parent":2,"fila":3},{"type":"bid-rama","parent":1,"child":5,"color":"purple","state":{"bid":[0,0,1,-1],"length":0,"turn":"lho"},"texts":{"0":"blalb","1":"hrhrhr ","2":"meee[r][s] fas","3":"[10] is 10 [d] no"}},{"type":"red-dot","parent":4,"fila":3},{"type":"bid-rama","parent":1,"child":7,"color":"green","state":{"bid":[0,0,1,5,0,0,0],"length":0,"turn":"lho"}},{"type":"bid-ctr","parent":6,"fila":3,"state":{"bid":[0,0,1,5,0,0,0],"contract":5,"declarer":"south"},"color":"yellow","playnode":8},{"type":"cpl-ctr","parents":[7],"fila":1,"trump":"n","declarer":"main","color":"yellow","child":9,"state":{"main":{"s":"a83","h":"kq84","d":"jt52","c":"94"},"rho":{"s":"kj92","h":"j3","d":"q93","c":"qj83"},"lho":{"s":"t7","h":"9765","d":"k87","c":"at76"},"cho":{"s":"q654","h":"at2","d":"a64","c":"k52"},"turno":"lho","trick":"","history":"","trNS":0,"trEW":0}},{"type":"cpl-rama","parent":8,"child":10,"fila":2,"color":"yellow","state":{"main":{"s":"a83","h":"kq84","d":"jt52","c":"94"},"rho":{"s":"kj92","h":"j3","d":"q93","c":"qj83"},"lho":{"s":"t7","h":"9765","d":"k87","c":"at76"},"cho":{"s":"q654","h":"at2","d":"a64","c":"k52"},"turno":"lho","trick":"","history":"c6c2cqc4c3c9ca","trNS":0,"trEW":0}},{"type":"red-dot","parent":9,"fila":2}]
I send this to php page using ajax for storage.
So far I have only made basic mysql queries, like insert username, password, etc.
But now it looks like I have to insert things in one table, then look at another, insert ids from previous register there, and this several times, etc.
I am troubled about something bad happening on the middle of the insertions leaving my database with inconsistent data, I remember I was taught that this should be done in one single step to avoid that, but I can't think of a way to do it.
I am troubled about something bad happening on the middle of the insertions leaving my database with inconsistent data, I remember I was taugth that this should be done in one single step to avoid that, but I can't think of a way to do it.
You need to do all that in a "transaction". Use InnoDB table type, and study about transactions. It's not rocket science, but needs some theory.
See http://www.mysqltutorial.org/mysql-transaction.aspx Then http://dev.mysql.com/doc/refman/5.1/en/ansi-diff-transactions.html