Working around InnoDB Contraints in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fjm
    Contributor
    • May 2007
    • 348

    #1

    Working around InnoDB Contraints in PHP

    Hi all, I'm new so please be forgiving if my question appears stupid.

    Thanks to Motoma and his fine class script, I was able to put together a very nice looking template.

    I am using mysql for the database and have the data pretty well normalized. The mysql tables are all set to use the Innodb engine which is a lot more strict than the regular Myisam.

    With Innodb, someone attempting to enter data into a child table before first entering the proper data into the parent table will have an error thrown. MyIsam is not this way, or at least that is not what I have experienced. This is what leads to wonder.

    When it comes to the point that I want to create an edit template for this db, and seeing as how my data is "here and there" throughout the database, I am wondering how to tell php or even if I need to.... to *first* put the data from textbox 1 into the parent table so the entire insert doesn't fail.

    In other words, if I have two tables like this:

    Code:
    Table1
    [u]table1_ID[/u]
    field1
    field2
     
    Table2
    [u]table2_ID[/u]
    [u]table1_ID[/u]
    field1
    field2
    and I have an insert form with all of the fields from table1 and table 2, the data will need to be inserted into table 1 first.

    How does one deal with this situation?
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Are you table structured dynamic? If not, you would just hard code the insert statements in order, or disallow users to manipulate children of parents that don't exist.

    Comment

    • fjm
      Contributor
      • May 2007
      • 348

      #3
      Originally posted by Motoma
      Are you table structured dynamic? If not, you would just hard code the insert statements in order, or
      The "Row format" is not set to dynamic if that is what you mean.

      So if I am understanding you Motoma, you say that I can write the insert statements "in the order of occurance"? In othe words,

      insert into table1values('1 ','2','somethin g');
      insert into table2 values('r','ff' ,'somethingelse ');

      Like that?

      Originally posted by Motoma
      disallow users to manipulate children of parents that don't exist.
      Matoma, what is the term for this so I can google it? I'm sorry, but I don't follow you on this one. Thanks

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by fjm
        The "Row format" is not set to dynamic if that is what you mean.

        So if I am understanding you Motoma, you say that I can write the insert statements "in the order of occurance"? In othe words,

        insert into table1values('1 ','2','somethin g');
        insert into table2 values('r','ff' ,'somethingelse ');

        Like that?
        That is exactly what I mean.

        Otherwise, don't show the user an option for creating a child if the parent does not yet exist.

        Comment

        • fjm
          Contributor
          • May 2007
          • 348

          #5
          Originally posted by Motoma
          That is exactly what I mean.

          Otherwise, don't show the user an option for creating a child if the parent does not yet exist.
          I got it Matoma. Thank you for clarifying that for me.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            No problem. Come back any time you have a question.

            Comment

            • fjm
              Contributor
              • May 2007
              • 348

              #7
              Originally posted by Motoma
              No problem. Come back any time you have a question.
              Thanks Motoma. I feel welcomed here and I really appriciate everyone helping me and looking past my newbish glow! :) I will return shortly, I'm sure.

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Changed thread title to better describe the problem (I think).

                Comment

                Working...