Fork me on GitHub

Problem with pnsearchapi and module  Bottom

  • First let me say that for me the upgrade process was pretty easy with very few snags. Excellent work everyone and thank you very much for providing an upgrade path and an excellent CMS. PostNuke was good, zikula rocks!

    I have upgraded to the latest zikula 1.0.2 and created the new search API for a module of mine in a pnsearchapi.php file. When I tested this on my dev server everything went fine. However on my production server I am getting weird errors. Either blank pages or SQL errors such as.

    Quote

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') FROM WHERE > '2008-11-06 16:00:06' AND > 0' at line 1
    SELECT COUNT(DISTINCT ) FROM WHERE > '2008-11-06 16:00:06' AND > 0


    This will only happen with certain search terms. You can test this out by going to
    http://www.microbiol…x.php?module=Search
    Try searching for bacteria, it works fine
    Then do a search for atp, it does not work.

    Here is the code for the search function from pnsearchapi.php in the Book Module.

    Code

    function book_searchapi_search($args)
    {
        pnModDBInfoLoad('Search');
        $pntable = pnDBGetTables();
        $artTable = &$pntable['book'];
        $artColumns = &$pntable['book_articles'];
       
        $searchTable = $pntable['search_result'];
        $searchColumn = $pntable['search_result_column'];

        $where = search_construct_where($args,
                                        array($artColumns['title'],
                                              $artColumns['contents']),
                                        null);

        $sessionId = session_id();
       
        $sql = "SELECT
                $artColumns[art_id] as id,
                $artColumns[title] as title,
                $artColumns[contents] as text,
                $artColumns[chap_id] as chap_id,
                $artColumns[book_id] as book_id
               FROM $artTable
                  WHERE $where"
    ;
                 
        $result = DBUtil::executeSQL($sql);
        if (!$result) {
            return LogUtil::registerError (_GETFAILED);
        }

        $insertSql =
    "INSERT INTO $searchTable
      ($searchColumn[title],
       $searchColumn[text],
       $searchColumn[extra],
       $searchColumn[created],
       $searchColumn[module],
       $searchColumn[session])
    VALUES "
    ;
       
       

        // Process the result set and insert into search result table
        for (; !$result->EOF; $result->MoveNext()) {
            $item = $result->GetRowAssoc(2);
            $chapter = pnModAPIFunc('Book', 'user', 'getchapter', array ('chap_id' => $item['chap_id']));
            $book = pnModAPIFunc('Book', 'user', 'get', array ('book_id' => $item['book_id']));
            // Security check -
            if (SecurityUtil::checkPermission('Book::Chapter', "$book[book_name]::$chapter[chap_name]", ACCESS_READ)) {
                $sql = $insertSql . '('
                       . '\'' . DataUtil::formatForStore($item['title']) . '\', '
                       . '\'' . DataUtil::formatForStore($item['contents']) . '\', ' //really the whole contents?
                       . '\'' . DataUtil::formatForStore($item['id']) . '\', '
                       . '\'' . DataUtil::formatForStore(DateUtil::getDatetime()) . '\', ' //not sure what to put here
                       . '\'' . 'Book' . '\', '
                       . '\'' . DataUtil::formatForStore($sessionId) . '\')';
                $insertResult = DBUtil::executeSQL($sql);
                if (!$insertResult) {
                    return LogUtil::registerError (_GETFAILED);
                }
            }
        }

        return true;
    }


    Any and all help is appreciated.

    Tim
  • So I am still stumped by this one and thought I would dig into the SQL statements. I noticed that Zikula has some very powerful debugging features, but I am having problems turning them on. In previous releases it was possible to get a log of all the SQL statements, but I am having a heck of a time getting this release to show me that info. I am sure if I can track down the SQL statement, I can fix this bug. So the question is, how do you turn on SQL logging. My suspicion is that the SQL statement being created causes a syntax error due to something funky in the title of the search terms, but I need to see the SQL statements to verify this. Any help appreciated.

    Tim
  • To all,

    I did some more digging. And it appears the information coming back from the search module is all fine. If I just ask the server to print that as the page, I get nicely formated search results, no matter what the search is. I know the errors are being thrown up during the search process, because if I remove the Book module search function by commenting out the code, the errors go away. I think I must be putting something funky in the search results table that is causing the problem.

    I REALLY need to find out where they are coming from. Can anyone help me to track down these SQL statements. Thanks.
  • Most important: A test/development server shall be a clone of your production server! That's why I do not recommend running xampp or similar. Either use Virtualbox or Vmware and install exactly the the same operating system version with all server applications as your target server is using (yes, that requires some work and knowledge), or simply create a sub-folder/sub-domain directly on your production host, with a clone of your site and a separate database for testing. That makes moving stuff actually working fine very easy, too.

    All your hard debugging work is useless if OS, web server, PHP and MySQL versions do not fit.

    Greetings,
    Chris



    edited by: slam, Nov 11, 2008 - 04:27 PM

    --
    an operating system must operate
    development is life
    my repo
  • Chris,

    Thanks for your reply. I did the due diligence and had this all working on a test server, I then did the upgrade on a sub-folder of the production server -- no problems. The exact same protocol was followed on the production server and this little bug popped up. This is just a minor weirdness that I would like to get worked out. Search works for most phrases and words, just a few give you some strangeness. I know it has to be something with my search code and its interaction with the content of the book. If I comment out the search code in the book module, I no longer see this, so clearly it is something my code is doing that did not appear in the test environment. Again, if I can look at all the SQL statements that are being sent, I am sure I can track this down.

    Tim



    edited by: Paustian, Nov 11, 2008 - 06:19 PM
  • I presume you've already checked you SQL statement thoroughly, just in case:

    In a _searchapi_search I recently experienced a more or less similar problem and found that something like

    Code

    select
                $artColumns[art_id] as id,


    did not look up the correct fields while

    Code

    select
                $searchTable.$artColumns[art_id] as id,


    did.
  • URRGGGGGH!!!!

    I found it. I cannot believe I was so stupid as to not see this. The mysql version on the server is 4.1.2. Zikula clearly states that its system requirement for mysql is 4.1.6 Ug. I will talk to my sys admin and see if he can do a mysql upgrade.



    edited by: Paustian, Nov 14, 2008 - 02:39 AM
  • [SOLVED!]
    I think I have the real solution now. Turns out the site was running PHP version 4.1.20; it was not the mysql version. So I did some more investigation and I was hitting a memory limit. Doing a search on the book is intensive, because there is a ton of text to plow through, and the script was running out of memory. This ended up giving me all the weird errors. The memory was set to 8M which is quite low. I have a request into my ISP to see if I can get that raised, but if they say they can't are there any suggestions on how to fix this? Thanks to everyone who tried to help.

    I cannot raise the memory limit in the .htaccess file. I tried icon_biggrin

This list is based on users active over the last 60 minutes.