Web
2006-12-12
使用Perl连接Mysql数据库
网站后台数据库转为Mysql,现在使用Perl连接数据库就方便多了。
通过DBI,Perl可以很容易的连接到数据库:
执行结果:#!/bin/perl
use DBI;
# Connect to target DB
my $dbh = DBI->connect("DBI:mysql:database=eygle;host=localhost","username","password", {'RaiseError' => 1});
# Insert one row
my $rows = $dbh->do("INSERT INTO test (id, name) VALUES (1, 'eygle')");
# query
my $sqr = $dbh->prepare("SELECT name FROM test");
$sqr->execute();
while(my $ref = $sqr->fetchrow_hashref()) {
print "$ref->{'name'}\n";
}
$dbh->disconnect();
[root@eygle ~]# perl test.cgi
eygle
以后很多统计数据可以直接通过Perl写入Mysql数据库,操作起来方便多了。
看来这次迁移是值得的:)
-The End-
历史上的今天
- 2016-12-12 2016中国软件大会:面向开发和DBA的Oracle 12.2新特性
- 2016-12-12 Oracle 数据库 12.2新特性手册-Core Improvements内核卷
- 2016-12-12 Oracle 12.2 新特性:Lockdown Profile 的多租户权限控制
- 2012-12-12 Oracle云数据库初体验 之二 - Application Express
- 2008-12-12 我家的小帅哥 - 爱夸张的盖小咪
- 2005-12-12 Oracle Diagnostics:Why sysdate is fixed?
- 2005-12-12 How to maintain Oracle10g Recyclebin?
- 2005-12-12 Definer and Invoker Rights
- 2004-12-12 天下无贼-那一滴金砂的缘起缘落
恭喜恭喜
最近一直关注你的网站,多跟你学习学习.
谢谢支持!
很强大。