Home > php教程 > php手册 > body text

PDO 通过 ODBC 批量插入 MSSQL 数据(dataAll)

WBOY
Release: 2016-06-07 11:40:16
Original
1251 people have browsed it

ThinkPHP 3.2.* 对 ODBC 支持不是很好。所以,这里写了一个方法来实现 dataAll 操作——随笔即兴所写。。。
function dataAll($arr, $table){<br>     if($arr){<br>         foreach($arr as $m => $var){<br>             $varKeyList = array_keys($var);<br>             $varCount = count($varKeyList);<br>             <br>             for($i = 0; $i                  $insertList .= $varKeyList[$i];<br>                 $insertValue .= "'".$var[$varKeyList[$i]]."'";<br>                 <br>                 if($i                      $insertList .= ",";<br>                     $insertValue .= ",";<br>                 }<br>             }<br>             <br>             // 生成 SQL 语句<br>             $sql = "insert ".$table."(".$insertList.") values(".$insertValue.")";<br>             <br>             <br>             $Model = new \Think\Model();<br>             $Model->query(UTF8toGB($sql));<br> <br>             $insertList = $insertValue = "";<br>         }<br>     }<br> }<br> <br> <br> // 编码转换(我的MSSQL 支持得是 GB2312)<br> function UTF8toGB($source){<br>     return iconv('UTF-8', 'gb2312//IGNORE', $source);<br> }其中 $arr 是数组,$table 是表。

AD:真正免费,域名+虚机+企业邮箱=0元

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