MySQL Batch Add

Source: Internet
Author: User

A bulk add-in package,

$data is a two-dimensional array, key corresponding to the field name of the data table;

/**
* Batch Creation
* @param array $data
* @return int $res affect line
* @author Wen
*/

Public Function Createmore ($data)
{
Processing data gets the name of the field to add data to
$sql _key = NULL;
$data _key = Array_keys ($data [0]);
foreach ($data _key as $k _k = $k _v) {
$sql _key. = '. $k _v. ', ';
}
$sql _key = substr ($sql _key,0,-1);
Processing data gets the data to be added
$sql _value = NULL;
foreach ($data as $v _k = $v _v) {
$sql _value. = ' (';
$data _v_data = array_values ($v _v);
foreach ($data _v_data as $v _d_k = $v _d_v) {
$sql _value. = "'". $v _d_v. "',";
}
$sql _value = substr ($sql _value,0,-1);
$sql _value. = '), ';
}
$sql _value = substr ($sql _value,0,-1);
Assembling SQL
$sql = ' INSERT into '. $this->g_table;
$sql. = ' ('. $sql _key. ') ';
$sql. = ' VALUES '. $sql _value;
$res = $this->execute ($sql);
return $res;
}

MySQL Batch Add

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.