php - Elegant Efficient way of inserting into a lot of tables MySQL -


i making survey , database has 19 tables , 100 columns. of them inserted required fields. looking elegant , efficient way of inserting many tables , columns. far have come create multidimensional array contains first key table name , second key column name field. below:

    $tablearray =  array(          'ownertable' => array(             'firstnamerow' => $firstname,             'lastnamerow' => $lastname         ),         'dealertable' => array(             'dealernamerow' => $dealername,             'dealercityrow' => $dealercity             )         );  foreach($tablearray $row => $key) {     foreach($tablearray[$row] $row1) {         $sql = "(insert $tablearray[$key] ($tablearray[$row]) values ($row1)";      }    } 

i didn't test code thinking along lines work. think 1 problem see separate insert each column instead of 1 insert each table. can work on writing code load values array @ once solve problem before start getting carried away want make sure not making big mistake , waste time if there better way it.

$tablearray =  array(          'ownertable' => array(             'firstnamerow' => $firstname,             'lastnamerow' => $lastname         ),         'dealertable' => array(             'dealernamerow' => $dealername,             'dealercityrow' => $dealercity             )         );  //it's bulj query execution in single statment; $i=1; $sql=""; foreach($tablearray $row => $key) {     foreach($tablearray[$row] $row1) {         //here can update value per row execution         if($i<=25)         {          $sql = $sql  + "(insert $tablearray[$key] ($tablearray[$row]) values ($row1);";          }         else         {             //execute sql statement here;             $i=0;             $sql="";         }     }    } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -