Perl操纵数据库

#!perl
use Win32::ODBC;
$Data = new Win32::ODBC("DSN=dhcp;UID=netman;PWD=netman;");
$Data2 = new Win32::ODBC("DSN=dhcp;UID=netman;PWD=netman;");
$Data1 = new Win32::ODBC("DSN=dhcp;UID=netman;PWD=netman;");
$Data3 = new Win32::ODBC("DSN=dhcp;UID=netman;PWD=netman;");

 


$Data->Sql("select ip,mac,host from dhcplist");

while ($Data->FetchRow())
{
 
 ($ip,$mac,$host) = $Data->Data;
 print $host,"\n";

  
 $Data1->Sql("select * from Employee ");
 
 while ($Data1->FetchRow())
 
 {
 ($cname,$dept,$dno,$id,$ext) = $Data1->Data;

 print "$cname","\n";
 print "$id","\n";
 


 }
 $Data1->Close();

 $flag = '';


 $Data2->Sql("select * from dhcp_data where host = '$host' and ip = '$ip' ");

        #print "select * from dhcp_data where host = '$host' and ip = '$ip'" ;

 while ($Data2->FetchRow())
        {
 
 #@flag = $Data2->Data;

 if ( $flag ne "" )
 {
 print "ok"; 
 
 $Data3->sql("update dhcp_data set ip = '$ip',host = '$host',mac ='$mac',cname = '$cname',dept = '$dept',dno = $dno',notesid = '$id',ext = '$ext',modifydate = getdate()"); 
    
 $Data3->Close();
  
 }
 else
 {
        print "ok2";
 $Data3->sql("insert into dhcp_data(ip,host,mac,cname,dept,dno,notesid,ext,modifydate) values('$ip','$host','$mac','$cname','$dept','$dno','$id','$ext',getdate())"); 
    
 $Data3->Close(); 
 }

}
 $Data2->Close(); 

 
  
}  
 
$Data->Close();


 

posted on 2010-04-09 10:02 明高 阅读(131) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2010年4月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

导航

统计

常用链接

留言簿

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜