zoukankan      html  css  js  c++  java
  • array_to_sql

    function array_to_sql($array, $type='insert', $exclude = array()){
        $sql = '';
        if(count($array) > 0){
            foreach ($exclude as $exkey) {
                unset($array[$exkey]);//剔除不要的key
            }
        
            if('insert' == $type){
                $keys = array_keys($array);
                $values = array_values($array);
                $col = implode("`, `", $keys);
                $val = implode("', '", $values);
                $sql = "(`$col`) values('$val')";
            }else if('update' == $type){
                $tempsql = '';
                $temparr = array();
                foreach ($array as $key => $value) {
                    $tempsql = "'$key' = '$value'";
                    $temparr[] = $tempsql;
                }
                $sql = implode(",", $temparr);
            }
        }
        return $sql;
    }
  • 相关阅读:
    10多媒体
    胡凡-01
    概念
    算法
    07Axios
    05VueCli
    04Vue.js路由系统
    03生命周期
    《穷人思维》学习感悟
    《基金》学习感悟之二
  • 原文地址:https://www.cnblogs.com/wanghaitao/p/9440322.html
Copyright © 2011-2022 走看看