2013-09-21 19:31
浏览 7


I'm somewhat new to mySQL and PHP. I have a little program that looks up a text's words in an etymological dictionary. -- Source here on github. It can only look up 1-3 words per second, which is a real limitation, especially when I'm trying to analyze a text that's bigger than a thousand words. Is there a way I can better structure my queries or database so that I can speed up this process?

Function that looks up a word:

function lookup($word) { 
    //connect to database
    $query="SELECT parent_lang FROM etym_dict WHERE word=\"$word\" and word_lang=\"eng\""; //making this English-only for now
    //debug_print("<p>Query is: $query</p>"); 
    or die("Failed to look up words in database."); 
    return $parent_lang; 

Thing that calls that function:

foreach (array_keys($results) as $word) { 
    if (!empty($parent_lang)) {  
        debug_print("$word, "); 
    } else { 
        $has_derivation= (strlen($derivation)>0) ? TRUE : FALSE; 
        if ($has_derivation) { 
        if(!empty($parent_lang) && $has_derivation) { 
            debug_print("<span class=\"blue\">$word ($derivation)</span>, "); 
        } else if(!empty($parent_lang)) { 
            debug_print("<span class=\"blue\">$word</span>, "); 
        } else { 
            debug_print("<span class=\"red\">$word"); 
            if ($has_derivation) { 
                debug_print("/$derivation</span>, "); 
            } else { 
                debug_print("</span>, "); 

Db query function:

 function dbquery($sql) {
                GLOBAL $dbc;
                return $result;

Db connect function:

function dbconnect() {
                  ... // redacted 
            ) or die ('Error connecting to database.');
            return $dbc;

Sample etym_dict dataDefinitions

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanmuybrtg1231 2013-09-21 20:33

    My first guess is that you don't have indexes on etym_dict, but that's only a guess because you haven't shown us the table definitions.

    解决 无用
    打赏 举报

相关推荐 更多相似问题