Because of working need,Want to will deposit the data in Sql Server database to guide entirely in Mysql database,Be in on the net related collect data,Find two kinds of methods,Talk about the view to them respectively now.
The first kind is installation Mysql ODBC,Those who use Sql Server derive function,Source of choice Mysql data,Derive directly into what linage occupies,This kind of method is very simple,But have a lot of corrupt practice in the light of actual application,The mainest reflecting is data type problem,Above all,In Sql Server database
Ntext, the data of the data type such as Image cannot be written directly in Mysql database,It is OK to should alter slightly only allegedly,Regrettablly occasionally this dish bird has not thought of how to alter,Next,Because design lieutenant general time to be set into Int in the database in Mysql occasionally model (those who save is time jab) ,Guide in data so after coming over,With respect to meeting occurrence conflict,Again,The field kind that the Mysql data that this kind of method generates expresses is very not right,So this is planted method I feel that this cannot be advocated.
The second kind is to use Php or Asp script to come to those who realize data to guide into the function,This kind of method needs to write a program,But flexibility is big,The operation also is not so difficult,Everything all is in your control,Introduce this method simply now
The Mysql environment that premise condition is you has been built,Build good cause database first,Build all watch structures with Sql statement again,All things is had now,Lack data only.
The data in the User watch that can realize database of the Mydb in Sql Server originally through the Php foot below guides to database of the Mydb in Mysql
%26lt; ?
$cnx = Odbc_connect('web' , 'admin' , the data source name that '123456');//'web' is the Mydb in Sqlserver,The user name that 'admin' is visit Mydb,'123456' is the password that visits Mydb
$cur= Odbc_exec($cnx, 'select * From User' );// opens the User table of database of the Mydb in Sql Server
$num_row=0;
$conn=mysql_pconnect("localhost" , "Root" , "Mysql of 123456");// join
@mysql_select_db('mydb' , $conn) Or
Die(" cannot receive a database repeatedly,Contact with the administrator please!") the Mydb database that;// opens MysqlWhile(Odbc_fetch_row($cur)) // takes out data one by one from the User watch in the Mydb library of Sql Server,If undertake choosing to data,The condition can be added to judge in the Select statement in front
{
$num_row++;
$field1 = Odbc_result($cur, the parameter I(1 here, 2, 3. . ) the I that those who point to is record concentration region,You can choose the ground to undertake choosing somewhat,The value that Fieldi gets corresponding region,Next you can undertake operating to 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);
The field that pair of Datetime types in Sql Server are here undertakes be changinged accordingly handling,The Int that changeover needs into me
$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;
}
? %26gt;
Put this paragraphs of script into Sql.php,Carry out on the server,Can get on the server the data in the User watch of database of the Mydb in Sql Server guides the User of database of the Mydb in Mysql goes in the watch.The operation of other watch and this is duplicate,not give uncecessary details.
The data of database of the Mydb in Asp script introducing to realize Sql Server again below guides to database of the Mydb in Mysql
%26lt;%Set Conn=server.createobject("adodb.connection" )Conn.open 'web' , 'admin' , the data source name that '123456' // 'web' is the Mydb in Sqlserver,The user name that 'admin' is visit Mydb,'123456' is the password that visits MydbSet 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, the Int that this Sql statement realized Filevalue From Senddate" // to change the Recdate field of Datetime type into Unix time jab
Rs.open Sql, conn, 1, 3Set Conn1=server.createobject("adodb.connection" )Conn1.open "myoa" , "Root" , "Q1-d6=7? "Q1-d6=7?? I=1Do While Not Rs.eofField1 = Rs(0)Field2 = Rs(1)Field3 = Rs(2)Field4 = Rs(3)Field5 = Rs(4)Sql1 = "insert Into User(ID, name, username, password, recdate)
Values(%26quot;%26amp;field1%26amp;%26quot; , '%26quot;%26amp;field2%26amp;%26quot;' , '%26quot;%26amp;field3%26amp;%26quot;' , '%26quot;%26amp;field4%26amp;%26quot;' , %26quot;%26amp;field5%26amp;%26quot;) %26quot;
Conn1.execute Sql1Rs.movenextI=i+1LoopRs.closeSet Rs=nothingConn.closeSet Conn=nothingConn1.closeSet Conn1=nothing
%%26gt;
Above is two to use the data that Php script and Asp script express to User to undertake arriving by Sql Server respectively of Mysql guide into meantime I use 2 kinds of evasive methods to avoid Ntext, of Image type data deliver,One kind is Nvarchar(4000) of Ntext field instead,Because of actual condition,The data length of this field in primitive data did not exceed 4000 words,Cut off without occurrence data so,Another method is Image kind data is taken in keeping a file,Save with file form,In putting file way the database,The method sees below:
Function Makeattach(fileContentType, filevalue, i)Select Case FileContentTypeCase "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 ElseExt="x "
End SelectIf Ext%26lt;%26gt;%26quot;x%26quot; ThenSet Fso=server.createobject("FileSystemObject" )FName=%26quot;attech%26quot;%26amp;i%26amp;%26quot; . "%26Amp;ext
Dir="d:aTtach "
If Fso.FileExists(Dir%26amp;FName) Then Fso.deletefile Dir%26amp;FName
If FName%26lt;%26gt;%26quot;%26quot; AND NOT Fso.FileExists(Dir%26amp;FName) Then
Set Strm1=Server.CreateObject("ADODB.Stream" )Strm1.OpenStrm1.Type=1 'BinaryStrm1.Write FilevalueStrm1.SaveToFile Dir%26amp;FName, 2
Set Strm1=NothingEnd IfMakeattach=fNameEnd IfEnd Function
This function has 3 inputs parameter,The first ContentType that is a file,The second binary system that is a file is numeric,The third is a variable that can distinguish file name,The suffixal name that puts a document certainly according to ContentType first,Save binary numerical value the file that designates file name namely next,Return file master to output parameter,The database middleman and guarantor that writes returned parameter Mysql as data is put.
Time is hurried,Sum up here first,Some help the person that hopes these characters can need to having,Take some of roundabout way less,Thank you read.:)
...