Home  >  Article  >  php教程  >  php 批量保存数据与批量更新数据

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

WBOY
WBOYOriginal
2016-06-08 17:29:091857browse
<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());
  }
 }

Statement:
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