[請益] PHP 執行exec()的問題
我想要用php來執行exec() 執行perl
先把資料庫裡存的網址抓下來
再去該網頁抓取內容 存進資料庫
我用cmd執行可以成功存進資料庫
但我用php去呼叫exec()函數 就無法將內容存進資料庫
但也沒有顯示錯誤訊息
想請問哪裡出錯了???
以下是我的程式碼
----------getnews.php----------------
$x=exec('cd desktop');//檔案在desktop
$z=exec('perl test1.pl');
print($x);
print($z);
---------test1.pl---------------------
use DBI;
my $dbh=DBI->connect("dbi:mysql:dbname=xxx","xxx",'xxx');#開啟資料庫
$sth = $dbh->do( "SET character_set_client ='utf8'");
$sth = $dbh->do( "SET character_set_connection='utf8'");
$sth = $dbh->do( "SET character_set_results='utf8'");
$sql1="select id from newsurl ORDER BY id DESC" ;
$k=$dbh->prepare($sql1);
$k->execute();
$a= $k->fetchrow_array();
$k->finish();
for($x=0;$x<=5;$x++){
$sql2="select url from newsurl where id='$a'" ;
$a-=1;
$k1=$dbh->prepare($sql2);
$k1->execute();
@result[$x] = $k1->fetchrow_array();
}
$k1->finish();
use WWW::Mechanize; # 使用這模組
use encoding 'utf-8';
my $agent1 = WWW::Mechanize->new();
for($y=0;$y<=5;$y++){
$agent1 -> get(@result[$y]);
my $content1 = $agent1 ->{content};
@title= $content1=~/<h1 class=\"headline\">(.*?)<\/h1>/g;
@time= $content1=~/\&ndash\;\ \;<abbr title=\"(.*?)T/;
@article= $content1=~/<p class=\"first\">(.*)<\/p>/g;
$sql3="insert into test1 (title, content, time) values
('@title','@article','@time')";#sql指令
$dbh->do( $sql3 );
}
$dbh->disconnect;#關閉資料庫
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.175.221
→
08/27 19:25, , 1F
08/27 19:25, 1F
→
08/29 10:36, , 2F
08/29 10:36, 2F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章