2013-01-04 3 views
0

죄송합니다 - 저는 초보자이므로 도움을 주시면 대단히 감사하겠습니다.MySQL 데이터베이스에서 문자 제거

내가 특정 문자가 필요 MySQL 데이터베이스의 열 (texty3)에서 약 30,000 항목이/단어 제거 :

특히, 3 자보다 짧은

아무 단어. capilised되지 않은 단어. 영숫자가 아닌 모든 것.

거기에 mysql 명령이 있는지 궁금한가요?

나는 누군가가, 다음과 같습니다 PHP를 통해

function getmtext($str) { 
    $text = ''; 
    $words = str_word_count($str, 1); 
    foreach ($words as $word) { 
     if ($word[0] >= 'A' && $word[0] <= 'Z') 
      if (strlen($word)>3) 
       $text .= $word.' '; 
    } 
    return $text; 
} 

을 미래를 업로드하는 스크립트를 작성했다 그러나 나는 이미 존재하는 항목을 편집하는 방법을 모르겠어요.

도움을 주셨습니다.

+1

PHP 스크립트를 작성하여 데이터베이스, MySQL 찾고있는 것을 수행하는 기능이 없습니다. – Stefan

답변

0

동일한 스크립트를 사용하여 SQL의 항목을 업데이트 할 수 있습니다. 순전히 SQL을 사용하여 요청한 방법은 없습니다.

그렇다면 (mysql 함수를 사용하여) 데이터베이스에서 데이터를 검색하고 정보를 수정하여 데이터베이스에 반환 할 수 있다고 말했습니다. 인수를 위해서

로컬 데이터베이스가 있다면, 루트로이 같은 것을 사용할 수 없음 암호 로깅라는 이름의 시험 :이 데이터베이스를 통해 이동하고 모든 단어를 제거하는 기능을 사용

function getmtext($str) { 
    $text = ''; 
    $words = str_word_count($str, 1); 
    foreach ($words as $word) { 
     if ($word[0] >= 'A' && $word[0] <= 'Z') 
     if (strlen($word)>3) 
      $text .= $word.' '; 
    } 
    return $text; 
} 

//set the database parameters 
$dbHost = "localhost"; 
$dbUser = "root"; 
$dbPass = ""; 
$dbName = "test"; 

//create the database connection 
$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error()); 
mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); 

//sql to get all texty3 rows from table 
$sql = "select id, texty3 from testtable"; 
$query = mysql_query($sql); //run the sql 
while($result = mysql_fetch_assoc($query)) { //loop through each row 
    $rowId = $result['id']; 
    $text = $result['texty3']; 
    $cleansedText = getmtext($text); 
    mysql_query("update testtable set texty3 = '$cleansedText' where id = '$rowId';"); 
} 

을 이 함수는 함수에 정의 된 매개 변수와 일치하지 않습니다. (죄송 합니다만이 코드를 확인할 수는 없지만 정확해야합니다. 적어도 가까운 것이어야합니다.)

+0

놀라운! 감사! –