perl 守护进程 Proc::Daemon::Init 与 DBI 的问题
我有一个如下所述的程序:
use DBI;
use Proc::Daemon;
Proc::Daemon::Init;
my $continue = 1; $SIG{TERM} = sub { $continue = 0 };
while ($continue) {
my $db=DBI->connect('DBI:mysql:xx;user=root;password=xxx');
my $sth=$db->prepare("select * from cpu_mem_calls ");
$sth->execute();
while (my @row=$sth->fetchrow_array()){
$x=$row[0]+200;
$y=$row[1]+200;
my $db_test=DBI->connect('DBI:mysql:xx;user=root;password=xxx');
my $sth=$db->prepare("insert into cpu_mem_calls values ($x,$y,'2011-03-21 17:19:00')");
$sth_test->execute();
$sth_test->finish();
$db_test->disconnect();
$sth->finish();
$db->disconnect();
sleep(5);
}
当我使用 Proc::Daemon::Init
模块 + DBI
时,我可以将值插入数据库,但是当我想从中选择一些值时数据库它不会工作。它不会返回任何值。这里面真正的问题是什么? DBI 在使用 Proc::Daemon::Init
运行时是否有任何问题?
I have a program as mentioned below:
use DBI;
use Proc::Daemon;
Proc::Daemon::Init;
my $continue = 1; $SIG{TERM} = sub { $continue = 0 };
while ($continue) {
my $db=DBI->connect('DBI:mysql:xx;user=root;password=xxx');
my $sth=$db->prepare("select * from cpu_mem_calls ");
$sth->execute();
while (my @row=$sth->fetchrow_array()){
$x=$row[0]+200;
$y=$row[1]+200;
my $db_test=DBI->connect('DBI:mysql:xx;user=root;password=xxx');
my $sth=$db->prepare("insert into cpu_mem_calls values ($x,$y,'2011-03-21 17:19:00')");
$sth_test->execute();
$sth_test->finish();
$db_test->disconnect();
$sth->finish();
$db->disconnect();
sleep(5);
}
I can insert values into database when I use Proc::Daemon::Init
module + DBI
but when I want to select some values from database it won't work. It won't return any value. What is the real issue in this? Does DBI have any issue in running with Proc::Daemon::Init
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经解决了这个问题...我试图从文件中读取一些IP...因为它是一个守护进程,它无法从文件中读取...我将所有内容放入一个数组中,一切都开始正常工作
I have resolved the issue...I was trying to read some IP's from a file...as its a daemon it cannot read from the file..I put all the things in an array and everything started working fine