Created
November 19, 2013 22:55
-
-
Save vasanthk/7554092 to your computer and use it in GitHub Desktop.
Huge Inserts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fields by type | |
$int_fields = [ | |
'permanent' => check_plain( $form_state['values']['additional']['permanent_directory'] ), | |
'app_id' => $app_info->id, | |
'level_1_field_id' => check_plain( $form_state['values']['level1']['level1_field'] ), | |
'level_2_field_id' => check_plain( $form_state['values']['level2']['level2_field'] ) | |
]; | |
$string_fields = [ | |
'permanent_empty_template' => $form_state['values']['additional']['permanent_empty_template'], | |
'name' => check_plain( strtolower($form_state['values']['level1']['name']) ) | |
]; | |
// Field names | |
$field_names = array_merge(array_keys($int_fields), array_keys($string_fields)); | |
$query_cols = implode(', ', $field_names); | |
// Placeholders | |
$placeholders = array_merge(array_fill(0, count($int_fields), '%d'), array_fill(0, count($string_fields), "'%s'")); | |
$query_placeholders = implode(', ', $placeholders); | |
// Values | |
$args = array_values($int_fields) + array_values($string_fields); | |
// Final Query | |
$insert_query = "INSERT INTO {app_directories} ($query_cols) VALUES ($query_placeholders)"; | |
// Run Query | |
array_unshift($args, $insert_query); | |
$result = call_user_func_array('db_query', $args); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment