分类: Mysql/postgreSQL
2008-05-30 09:37:09
以下为引用的内容: $cnx = odbc_connect('web', 'admin', '123456');//'web'是sqlserver中mydb的数据源名,'admin'是访问mydb的用户名,'123456'是访问mydb的密码 $cur= odbc_exec( $cnx, 'select * from user' );//打开sql server中mydb数据库的user表 $num_row=0; $conn=mysql_pconnect("localhost","root","123456");// 连接mysql @mysql_select_db('mydb',$conn) or die("无法连接到数据库,请与管理员联系!");//打开mysql的mydb数据库 while( odbc_fetch_row( $cur )) //从sql server的mydb库中的user表逐条取出数据,如果对数据进行选择,可在前面的select语句中加上条件判断 { $num_row++; $field1 = odbc_result( $cur, 1 ); // 这里的参数i(1,2,3..)指的是记录集中的第i个域,你可以有所选择地进行选取,fieldi得到对应域的值,然后你可以对fieldi进行操作 $field2 = odbc_result( $cur, 2 ); $field3 = odbc_result( $cur, 3 ); $field4 = odbc_result( $cur, 4 ); $field5 = odbc_result( $cur, 5 ); $field6 = odbc_result( $cur, 6 ); $field5 = timetoint($field5); //这里是对sql server中的datetime类型的字段进行相应转换处理,转换成我所需要的int型 $querystring = "insert into user (id,name,username,password,recdate) values('$field1','$field2','$field3','$field4','$field5')" ; mysql_query($querystring,$conn); } function timetoint($str){ $arr1=split(" ",$str); $datestr=$arr1[0]; $timestr=$arr1[1]; $arr_date=split("-",$datestr); $arr_time=split(":",$timestr); $year=$arr_date[0]; $month=$arr_date[1]; $day=$arr_date[2]; $hour=$arr_time[0]; $minute=$arr_time[1]; $second=$arr_time[2]; $time_int=mktime($hour,$minute,$second,$month,$day,$year); return $time_int; } ?> |
以下为引用的内容: <% set conn=server.createobject("adodb.connection") conn.open 'web', 'admin', '123456' // 'web'是sqlserver中mydb的数据源名,'admin'是访问mydb的用户名,'123456'是访问mydb的密码 set rs=server.createobject("adodb.recordset") sql="select ID,name,username,password,datediff(s,'1970-01-01 00:00:00',recdate)-8*3600,reid,filename,fileContentType,filevalue from senddate" //这条sql语句实现了将datetime类型的recdate字段转化成unix时间戳的int型 rs.open sql,conn,1,3 set conn1=server.createobject("adodb.connection") conn1.open "myoa","root","q1-d6=7?" i=1 do while not rs.eof field1 = rs(0) field2 = rs(1) field3 = rs(2) field4 = rs(3) field5 = rs(4) sql1 = "insert into user(ID,name,username,password,recdate) values("&field1&",'"&field2&"','"&field3&"','"&field4&"',"&field5&")" conn1.execute sql1 rs.movenext i=i+1 loop rs.close set rs=nothing conn.close set conn=nothing conn1.close set conn1=nothing %> |
以下为引用的内容: function makeattach(fileContentType,filevalue,i) select case fileContentType case "application/msword" ext="doc" case "application/vnd.ms-excel" ext="exl" case "application/vnd.ms-powerpoint" ext="pps" case "application/x-rar-compressed" ext="rar" case "application/x-zip-compressed" ext="zip" case "image/gif" ext="gif" case "image/pjpeg" ext="jpg" case "text/plain" ext="txt" case else ext="x" end select if ext<>"x" then set fso=server.createobject("FileSystemObject") fName="attech"&i&"."&ext Dir="d:attach" If fso.FileExists(Dir & fName) Then fso.deletefile Dir & fName If fName<>"" AND NOT fso.FileExists(Dir & fName) Then Set strm1=Server.CreateObject("ADODB.Stream") strm1.Open strm1.Type=1 'Binary strm1.Write filevalue strm1.SaveToFile Dir & fName,2 Set strm1=Nothing end if makeattach=fName end if end function |