连接到数据库Perl

连接到数据库Perl

本文介绍了连接到数据库Perl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码连接到mysql数据库:

I am connecting to a mysql database using the following code:

my $dbh = DBI->connect("DBI:mysql:test:localhost", $user, $pass)
    or die $DBI::errstr;
my $sqlQuery  = $dbh->prepare($query)
    or die "Can't prepare $query: $dbh->errstr\n";
my $rv = $sqlQuery->execute
    or die "can't execute the query: $sqlQuery->errstr";

while (my @row= $sqlQuery->fetchrow_array()) {
    # do something;
}

我的疑问是:直到我的应用程序与小型DB进行交互之前,都很好.但是,当我将此应用程序移到数据库大小可能在100 GB的实时环境中时,此代码可能会导致什么性能问题.实际上,我要问的是在线-

My doubt is: It is fine till the time my application is interacting with small DBs. But when I move this application to a live environment where the DB size may be in 100s of GBs, what performance issues can this code cause. Effectively what I am asking is, at the line -

@row= $sqlQuery->fetchrow_array();

Perl将复制整个表内容并将其转储到变量中.如果可以,这是否会对我的应用程序和数据库服务器造成严重的性能问题?

Will Perl copy the entire table contents and dump it into the variable. If yes, won't it cause significant performance issues for my application as well as the database server?

推荐答案

在此行:

@row= $sqlQuery->fetchrow_array();

数据库将向perl返回一行数据,如果与海量数据库进行交互,则不会将查询的整个结果集都转储到变量中.

One row ata time will be returned by the database to perl, if interacting with a massive database you will not dump the entire result set of the query to a variable.

$arrRef = $sqlQuery->fetchall_arrayref();

另一方面.

这篇关于连接到数据库Perl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:36