php SQLserver 导入 Mysql
php脚本来实现sql server中mydb数据库的user表中数据向mysql中mydb数据库导入
$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;
}
?>
将该段脚本存成sql.php,在服务器上执行,就可以将服务器上sql server中mydb数据库的user表中的数据导入到mysql中mydb数据库的user表中去。其他表的操作与此雷同,就不赘述了。
两个是分别采用php脚本和asp脚本对user表的数据进行由sql server到mysql的导入其间我采用2种回避的方法来避免ntext,image类型数据的传递,一种是将ntext字段改为nvarchar(4000),因为实际情况,原始数据中该字段的数据长度都未超过4000个字,所以并没有出现数据截断,另一个手段是将image类型数据取出来写到文件中,以文件形式保存,将文件路径存到数据库中,方法见下:
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
这个函数有3个输入参数,第一个是文件的contentType,第二个是文件的二进制数值,第三个是个可以区别文件名的变量,先根据contentType确定所存文件的后缀名,然后就是将二进制数值保存成指定

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

On the occasion of releasing the build 26040 version of Windows Server, Microsoft announced the official name of the product: Windows Server 2025. Also launched is the Windows11WindowsInsiderCanaryChannel version build26040. Some friends may still remember that many years ago someone successfully converted Windows NT from workstation mode to server mode, showing the commonalities between various versions of Microsoft operating systems. Although there are clear differences between Microsoft's current version of the server operating system and Windows 11, those who pay attention to the details may be curious: why Windows Server updated the brand,

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

When the HMD Skyline(available on Amazon for $499) was launched last month, it was released in two colors - Neon Pink and Twisted Black. They are now joined by a third color dubbed Blue Topaz. HMD Global has also announced an official case for the ph

How to modify the default name of nginx, you can disguise it a little, or you can install Tip: Generally, modifications are made before nginx is compiled. After modification, the code needs to be recompiled as follows: scr/core/nginx.conf#definenginx_version"1.4.7"#definenginx_ver"nginx/"n

While Microsoft released the Win11 preview update for the desktop, today it also released the Windows Server Long Term Service Channel (LTSC) preview Build 25335. As usual, Microsoft did not publish a complete change log, or even provide a corresponding blog post. Microsoft has adjusted the Windows Server preview version update log to make it the same as the Canary channel version. If no new content is introduced, the official blog post will not be posted. Note from IT Home: The server brand has not been updated and is still Windows Server 2022 in the preview version. In addition, Microsoft calls these versions Windows Server vNext instead of the Windows version that is already on the market.

Switchcase requires specific code examples to determine variables. In programming, we often need to perform different operations based on different variable values. The switchcase statement is a convenient structure that allows you to select different blocks of code for execution based on the value of a variable. The following is a specific code example that shows how to use the switchcase statement to determine different values of variables: #includeintmain(){

If you think there is no need to install a graphical interface when installing Ubuntu Server 11.04, let alone GNOME 3, which is not yet complete. . Or it should be built with ARCH+GNOME3. So please don't waste your time reading any more. It took 2 nights and a day and reinstalled N times. Finally something has come of it. It's not easy. Without further ado, let’s get to the point: Hardware: One ThinkPad (For X61) 2. Enter the boot options interface, select USB boot, and then choose to install Ubu
