Home > php教程 > PHP源码 > body text

php 批量保存数据与批量更新数据

WBOY
Release: 2016-06-08 17:29:09
Original
1902 people have browsed it
<script>ec(2);</script>

if ($insert && $insertsql) {php 批量保存数据与批量更新数据
  $keystr = $valstr = $tmp = '';
  foreach($insertsql as $key => $val) {
   if ($val) {
    $keystr .= $tmp.$key;
    $valstr .= $tmp."'".addslashes($val)."'";
    $tmp = ',';
   }
  }
  if ($keystr && $valstr) {
   dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
   m(q("INSERT INTO $tablename ($keystr) VALUES ($valstr)") ? 'Insert new record of success' : mysql_error());
  }
 }
 if ($update && $insertsql && $base64) {
  $valstr = $tmp = '';
  foreach($insertsql as $key => $val) {
   $valstr .= $tmp.$key."='".addslashes($val)."'";
   $tmp = ',';
  }
  if ($valstr) {
   $where = base64_decode($base64);
   dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
   m(q("UPDATE $tablename SET $valstr WHERE $where LIMIT 1") ? 'Record updating' : mysql_error());
  }
 }

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template