Home > Backend Development > PHP Tutorial > php MySql function example to insert into array

php MySql function example to insert into array

WBOY
Release: 2016-07-25 08:56:28
Original
1323 people have browsed it
This article introduces a custom function for inserting arrays into the MySQL database in PHP. Friends in need can refer to it.

php implements the function of inserting an array into the mysql database. The code is as follows:

<?php
/**
* 保存数组数据到mysql
* by bbs.it-home.org
*/
public function insertData($table,$data){
       $field=implode(',', array_keys($data));
       foreach (array_values($data) as $key=>$val){
        $value .="'".$val."'";
        if ($key<count($data)-1)
        $value .=",";
}
 $sql= "INSERT INTO ".$table."(".$field.") values(".$value.")";
        return $this->insert($sql);
}
?>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template