Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
php mysql speed insert
$userData = array();
foreach ($userList as $user) {
$userData[] = '("' . $user['first_name'] . '", "' . $user['last_name'] . '")';
}
$query = 'INSERT INTO users (first_name,last_name) VALUES' . implode(',', $userData);
==========>>>>>>>>
INSERT INTO users (first_name,last_name) VALUES("John", "Doe"),("Jane", "Doe")...
//////////////////////////////////////////////////
$query = 'INSERT INTO `item_return` ( `return_type`, `return_remaks`, `user_id`, `rep_order_id`, `item_id`, `return_price`, `return_quantity`) VALUES ';
$pack = array();
foreach ($market_return as $sr) {
$valLine = "('market','" . $sr['return_remaks'] . "','" . $emp_id . "'," . $sr['id_sales_order'] . ",'" . $sr['id_item'] . "'," . -1 . "," . $sr['item_qty'] . ")";
array_push($pack, $valLine);
}
$query .= implode(",", $pack);
$this->db->doQuery($query);
for ($i = strlen($fip_query) - 1; $i > 0; $i--) {
if ($fip_query[$i] == ',') {
$fip_query[$i] = '';
} else {
break;
}
}
//////////////////////////////////////
$count = $dataArray['count2'];
$sql = "INSERT INTO `outlet_stock_check` (`outlet_name`, `outlet_id`, `product_name`, `product_id`, `qty`) VALUES ";
$do = FALSE;
for ($index = 0; $index < $count; $index++) {
if (isset($dataArray['product_name_' . $index]) && !empty($dataArray['product_qty_' . $index])) {
$sql.="('" . $all_userdata['oname'] . "', " . $all_userdata['id_outlet'] . ", '" . $dataArray['product_name_' . $index] . "', " . $dataArray['product_id_' . $index] . "," . $dataArray['product_qty_' . $index] . ")";
if (!$do) {
$do = TRUE;
}
if ($index + 1 < $count) {
$sql.=",";
}
}
}
if ($do) {
// echo $sql;
$this->db->query($sql);
$newdata = array(
'l1' => 1
);
$this->session->set_userdata($newdata);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.