2012-05-10 5 views
1

빠른 질문은 여기 RSS 피드를 실행하는 프로세스가 있고이를 mySQL 데이터베이스에 추가합니다.PHP에서 작업이 끝나기 전에 다음 항목으로 이동하기 전에

이 과정에서 필자는 가독성 API를 사용하여 URL 콘텐츠를 가져올 것입니다.

이제 단일 항목에서 제대로 작동하지만이 스크립트는 수백 개의 항목을 가질 수 있으므로 아무 것도 내 데이터베이스에 삽입되지 않습니다.

내가 프로세스를 끝내고 즉시 RSS의 다음 항목으로 건너 뛸 수 있는지 궁금합니다.

누구든지 계속 진행하기 전에 끝내는 방법을 제안 할 수 있습니까? 아래 코드 :

$db_hostname="localhost"; 
$db_username="myusername"; 
$db_password="mypassword"; 

try 
{ 
/* query the database */ 

$db = mysql_connect($db_hostname,$db_username,$db_password); 
if (!$db) 
{ 
    die("Could not connect: " . mysql_error()); 
} 
mysql_select_db("MyDB", $db); 


// Get stories that don't have a the readability assigned 
$query="select item_id, item_url from tw_articles_parse where story_readability = '' LIMIT 0 , 1"; 
$result=mysql_query($query); 
$num=mysql_numrows($result); 
// Close the DB connection 
mysql_close(); 


// Start the loop of source RSS feeds 
$i=0; 
while ($i < $num) { 

    $item_url=mysql_result($result,$i,"item_url"); 
    $item_id=mysql_result($result,$i,"item_id"); 

    // Parse the story URL into the Readability API 
     $url = "https://www.readability.com/api/content/v1/parser?url=$item_url&token=myapikey"; 
     // Get the contents of the JSON returned by the API 
     $json = file_get_contents($url); 
     // Decode the JSON 
     $out = json_decode($json, true); 
     // Set the content as a variable 
     $story = mysql_real_escape_string($out['content']); 

     // Insert into the DB - Adding 0 to story_club_id as default 
     $item_insert_sql = "UPDATE tw_articles_parse SET story_readability=$story WHERE item_id='" . $item_id . "'"; 
     $insert_item = mysql_query($item_insert_sql, $db); 



$i++; 
}// end the loop of feeds 


    } catch (Exception $e) 
{ 
echo 'Caught exception: ', $e->getMessage(), "\n"; 
} 
+0

거야? – PeeHaa

+1

고대의'mysql_ *'함수로 새로운 코드 작성을 중단하십시오. 그들은 더 이상 유지되지 않으며 커뮤니티는 [비추천 프로세스]를 시작했습니다 (http://news.php.net/php.internals/53799). 대신 준비된 구문을 배우고 [PDO] (http://php.net/pdo) 또는 [MySQLi] (http://php.net/mysqli)를 사용해야합니다. 만약 당신이 배울 점이 있다면, 여기 [PDO 관련 튜토리얼] (http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers). –

+1

당신의 SET이 아니길 바랍니다 story_readability = '$ story' – gunnx

답변

0

아마 아무것도 당신이 UPDATE 문을 사용하고 있기 때문에 삽입되지 갱신이 ITEM_ID을 correspoding에 그런 기록이 단순히하지? DUPLICATE KEY UPDATE ON ... UPDATE 쿼리를 삽입하려면를 변경해보십시오

불행하게도 우리가 데이터베이스 스키마를 모르겠지만,이 같은 일을해야 : 모든 태그가 무엇을

$item_insert_sql = "INSERT INTO tw_articles_parse (story_readability, item_id) VALUES ('$story', $item_id) ON DUPLICATE KEY UPDATE story_readability='$story'"; 
0

혹시 시간이 얼마 남지 않았습니까? 경고 및 오류보고를 활성화합니다

ini_set("display_errors", 1); 
error_reporting(E_ALL); 
관련 문제