好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Windows和Linux系統下perl連接SQL Server數據庫的方法

Windows和Linux系統下perl連接SQL Server數據庫的方法

熱門標簽:萬利達百貨商場地圖標注 okcc外呼系統怎么調速度 電話機器人哪里有賣 熱門電銷機器人 上海企業外呼系統 河南虛擬外呼系統公司 外呼電信系統 惠州龍門400電話要怎么申請 智能機器人電銷神器

本文將提供一些perl連接Microsoft SQL Server數據庫的實例。perl腳本運行在Windows和Linux平臺。

Windows平臺

如果在Windows平臺下運行perl腳本,建議使用依賴DBI的兩個模塊包,提供標準的數據庫接口模塊。

DBD::ODBC
DBD::ADO

使用DBD::ODBC

如果選用DBD::ODBC,下面的實例代碼將展示如何連接到SQL Server數據庫:

復制代碼 代碼如下:

use DBI;
 
# DBD::ODBC
 
my $dsn = 'DBI:ODBC:Driver={SQL Server}';
my $host = '10.0.0.1,1433';
my $database = 'my_database';
my $user = 'sa';
my $auth = ‘s3cr3t';
 
# Connect via DBD::ODBC by specifying the DSN dynamically.
my $dbh = DBI->connect("$dsn;Server=$host;Database=$database",
 $user,
 $auth,
 { RaiseError => 1, AutoCommit => 1}
 ) || die "Database connection not made: $DBI::errstr";
 
#Prepare a SQL statement my $sql = "SELECT id, name, phone_number FROM employees ";
my $sth = $dbh->prepare( $sql );
 
#Execute the statement
$sth->execute();
 
my( $id, $name, $phone_number );
 
# Bind the results to the local variables
$sth->bind_columns( undef, \$id, \$name, \$phone_number );
 
#Retrieve values from the result set
while( $sth->fetch() ) {
 print "$id, $name, $phone_number\n";
}
 
#Close the connection
$sth->finish();
$dbh->disconnect();

你還可以使用預先設置的一個系統DSN來連接。要建立一個系統DSN,可以這樣訪問控制面板->管理工具->數據源。

使用系統DSN連接,需要更改連接字符串。如下所示:

復制代碼 代碼如下:

# Connect via DBD::ODBC using a System DSN
my $dbh = DBI->connect("dbi:ODBC:my_system_dsn",
 $user,
 $auth,
 {
 RaiseError => 1,
 AutoCommit => 1
 }
 ) || die "Database connection not made: $DBI::errstr";

使用DBD::ADO

如果選擇DBD::ADO模塊,下面的實例展示如何連接到SQL Server數據庫。

復制代碼 代碼如下:

use DBI;
 
my $host = '10.0.0.1,1433';
my $database = 'my_database';
my $user = 'sa';
my $auth = ‘s3cr3t';
 
# DBD::ADO
$dsn = "Provider=sqloledb;Trusted Connection=yes;";
$dsn .= "Server=$host;Database=$database";
my $dbh = DBI->connect("dbi:ADO:$dsn",
 $user,
 $auth,
 { RaiseError => 1, AutoCommit => 1}
 ) || die "Database connection not made: $DBI::errstr";
 
#Prepare a SQL statement
my $sql = "SELECT id, name, phone_number FROM employees "; my $sth = $dbh->prepare( $sql );
 
#Execute the statement
$sth->execute();
 
my( $id, $name, $phone_number );
 
# Bind the results to the local variables
$sth->bind_columns( undef, \$id, \$name, \$phone_number );
 
#Retrieve values from the result set
while( $sth->fetch() ) {
 print "$id, $name, $phone_number\n";
}
 
#Close the connection
$sth->finish();
$dbh->disconnect();

Linux平臺

如果是在Linux平臺下運行perl腳本,連接SQL Server數據庫需要使用到DBD::Sybase包。

安裝SQL Server支持庫

Sybase DBD包依賴FreeTDS驅動程序。

FreeTDS下載地址:www.freetds.org

安裝FreeTDS驅動的說明文檔參見:http://www.freetds.org/userguide/config.htm

該驅動沒有使用到ODBC.

配置數據源

修改freetds.conf文件包括SQL Server數據庫信息,如下所示:

復制代碼 代碼如下:

[SS_MY_DB]
host = 10.0.0.1 # or host name port = 1433
tds version = 7.0

安裝Sybase DBD模塊

該模塊文檔參見:http://search.cpan.org/~mewp/DBD-Sybase/Sybase.pm

此外,需要將sybase環境變量應設置為FreeTDS安裝路徑,export SYBASE=/usr/local/freetds

使用Sybase DBI和SQL Server DSN實例

復制代碼 代碼如下:

# load the DBI module
use DBI;
use DBD::Sybase;
 
my $database="my_database";
my $user="sa";
my $auth="s3cr3t";
 
BEGIN
{
 $ENV{SYBASE} = "/usr/local";
}
 
# Connect to the SQL Server Database
my $dbh = DBI->connect("dbi:Sybase:server=ss_my_db;database=$database",
 $user,
 $auth
 {RaiseError => 1, AutoCommit => 1}
 ) || die "Database connection not made: $DBI::errstr";
 
#Prepare a SQL statement
my $sql = "SELECT id, name, phone_number FROM employees";
my $sth = $dbh->prepare( $sql );
 
#Execute the statement
$sth->execute();
 
my( $id, $name, $phone_number );
 
# Bind the results to the local variables
$sth->bind_columns( undef, \$id, \$name, \$phone_number );
 
#Retrieve values from the result set
while( $sth->fetch() ) {  print "$name, $title, $phone\n";
}
 
#Close the connection
$sth->finish();
undef $sth; # This fixes a segfault bug with certain versions of DBD::Sybase
$dbh->disconnect();

您可能感興趣的文章:
  • 讓apache2以cgi方式運行perl cgi程序的實現方法
  • windows下Apache+MySql+PHP3+PHP4+PERL安裝配置
  • Win2000+Apache+MySql+PHP4+PERL安裝使用小結
  • Windows Server 2016 上配置 APACHE+SSL+PHP+perl的教程詳解

標簽:百色 綏化 周口 淮安 合肥 綿陽 秦皇島 周口

巨人網絡通訊聲明:本文標題《Windows和Linux系統下perl連接SQL Server數據庫的方法》,本文關鍵詞  Windows,和,Linux,系統,下,perl,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Windows和Linux系統下perl連接SQL Server數據庫的方法》相關的同類信息!
  • 本頁收集關于Windows和Linux系統下perl連接SQL Server數據庫的方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 日本公妇手机在线观看| 久久婷婷五月综合国产尤物app| 吉林市| 太大太长太粗太硬受不了| 精品欧美一区二区久久久伦| 在线播放成人A片??麻豆网站| 乱h群高h| 国产亚洲精品xxx| 阿娇13分49秒无删减在线观看| 717亚洲欧美日韩AV无码| 臣服在同学胯下黑子| 国产福利片在线观看| 女人下边被添全过程A片不盖被子 用舌头去添高潮无码免费软件 | 91精品国产国拍一二三产品价格| 跪吞含主人伺候| 午夜dj视频观看在线播放www| 激情网在线| 免费一级婬片A片啪啪声故事| 痴女勃起寸止榨干精在线播放 | 中春药后她被NP了NPH| 亚洲天天做日日做天天爽| 电车美人| jizz亚洲高清在线观看| YSL蜜桃色黄| 接电话高潮不小心叫出了声来| 黄瓜视频成人A片免费观看| 厦门大学女厕照传网络在线观看 | 亚洲天堂在线视频| 五月婷视频| 欧美精产国品一二三产品特点| 美女被舔下面| 色娜娜在线视频免费观看| 真人无遮挡120秒试看片片| 亚洲蜜桃精久久久久久久久久久久| 91视频app污| 男男受被强做开腿呻吟| 19+韩国美女vip视频| 刺激cijilu福利区在线观看| 黄色的视频免费| 美女扒开屁股胸无遮挡| 门卫老李干了校花琦琦视频|