这篇文章主要介绍怎么通过perl 的DBI 模块来操作sql 数据库。本文假设你已经了解了SQL的基本用法和perl 语言。

 一      perl下如何连接sql。

DBI下有很多方法都可以连接到sql, 本例介绍的方法只是其中的一种,它使用的是ODBC。读者可以尝试使用mysql等。实例如下:

;

 

二      接下来看如何创建一个表以及表的相关insert, update, delete等操作。

      1  建立一个表:

$SQL= "create table [user](ID integer primary key identity(1, 1), username text not null, password text not null, email text not null)";

$CreateTable = $dbh->do($SQL);

 

      2   insert update和delete

);

 

      3  读取数据:

$SQL= "select * from [user]";

$Select = $dbh->prepare($SQL);
$Select->execute();

while($Row=$Select->fetchrow_hashref)
{
  
print "$Row->{username} $Row->{email}";
}

 

--- END

相关文章:

  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2021-12-19
  • 2022-02-27
  • 2021-10-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-01-18
相关资源
相似解决方案