用Win32::ODBC 操作sql2000 示例

用Win32::ODBC 操作sql2000 示例

用Win32::ODBC 操作sql2000 示例
############################连接sql2000
use Win32::ODBC;

#SERVER# DSN数据库名# UID数据库管理账号#数据库密码#DBALIAS数据库别名

my $connstr ="DRIVER={SQL Server};SERVER=127.0.0.1;DSN=LocalSever;UID=sa;PWD=0213sy;Database=WebNews";

my $data = new Win32::ODBC($connstr) or die "$!";

print "连接成功";

###############################查询纪录数

$FORM{subject} = "Facebook刺激中国SNS社区发展";

$sql = "select count(*) from [dbo].[WebNews] where WebNewsTitle = '$FORM{subject}';";


$data->Run("$sql");

$data->FetchRow();

my $num = $data->Data();


print "找到 $num 篇文章";

#######################插入数据

my $WebNewsTitle = "Facebook刺激中国SNS社区发展";
my $WebNewsClassID = "13";
my $WebNewsContent = "测试,请不要删除!";
my $WebNewsPic = "fd";
my $WebNewsFrom = "《信息-mala-周刊》";
my $WebNewsTime = "getdate()";

my $WebNewsRead = "2";

my $sql = "INSERT INTO [dbo].[WebNews] (WebNewsTitle,WebNewsClassID,WebNewsContent,WebNewsPic,WebNewsFrom,WebNewsTime,WebNewsRead)
values ('$WebNewsTitle','$WebNewsClassID','$WebNewsContent','$WebNewsPic','$WebNewsFrom',$WebNewsTime,'$WebNewsRead');";
$data->Run("$sql");

print "插入数据结束";

$data->Close; #关闭数据库连接




   

我在用cpan进行安装模块时.
我在用cpan进行安装odbc模块时 出错。。。

OS unsupported
Running make test
 Make had some problems, maybe interrupted? Won't test
Running make install
 Make had some problems, maybe interrupted? Won't install


难道说 就支持在windows下的perl?




   

Win32::ODBC
貌似只能在win下用

linux 要用DBI
对,只在win下用.