Forums

Database error after 1.5 -> 2.0 upgrade: SELECT COUNT(DISTINCT ID) FROM (20 posts)

  1. tropos
    Member
    Posted 6 years ago #

    Hello,

    after i've upgraded from wordpress 1.5 to 2.0, i'm getting this error message after my oldest post (at the very bottom):

    WordPress database error: [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 '' at line 1]
    SELECT COUNT(DISTINCT ID) FROM

    also, when i display posts in a category (or by a user or a month), i get the same message but it's at the top.

    all posts are actually displayed correctly.

    i'm running:
    Apache/2.0.53 (Linux/SUSE)
    PHP/4.3.10
    MySQL 4.1.10a-log
    WP 2.0.2

    can you, please, help?

    thanks and have a nice day,

    =martin=

    ps. sorry, no link, the blog is behind a firewall.

  2. Austin Matzko
    Member
    Posted 6 years ago #

    Did you run /wp-admin/upgrade.php ? The database structure has changed since 1.5.

  3. evilhomer
    Member
    Posted 6 years ago #

    I have this error also.
    I ran upgrade.php.

    my blog is viewable at http://www.webdevireland.com/blog/

  4. tropos
    Member
    Posted 6 years ago #

    filosofo: yes, i ran upgrade.php right after i upgraded to 2.0.

  5. Austin Matzko
    Member
    Posted 6 years ago #

    For those of you who are getting this problem, did you replace the 1.5 .htaccess file with the 2.0 one? In other words, are you using the internal permalinks rewriting system?

  6. tropos
    Member
    Posted 6 years ago #

    filosofo: in 1.5 i was using the "almost pretty" permalinks (without mod_rewrite). i've just found out that when i upgraded to 2.0, it was automatically switched to default with the parameter (?p=123), but now i switched back to the original "almost pretty" permalinks (/index.php/%year%/%monthnum%/%day%/%postname%/). i'm still getting the same error message.

  7. Austin Matzko
    Member
    Posted 6 years ago #

    So you were getting the error even with the default permalinks setting (in other words, when your links were all like /?p=123)?

    Is this a Windows or Unix/Linux server?

    To help diagnose the problem, copy the dump environment plugin to a file such as dump_env.php (Make sure there are no spaces before the first <?php or after the last ?>. Then change the third line of the plugin from $hide = true; to $hide = false;

    Put it in your plugins directory, and activate it.

    Then at the bottom of your WordPress posts and pages there is a lot of interesting data. On the pages that produce the error, I'd like to know the first block of stuff immediately after "Environment Dump," such as REQUEST_URI, QUERY_STRING, FILE, WP Query String, and WP Query Query String.

    Also, under the heading "WP_Query" you should see something like
    wp_query Object
    (
    [request] => SELECT . . .

    I'd like to know what that [request] is on your error pages.

  8. evilhomer
    Member
    Posted 6 years ago #

    HOME: http://www.webdevireland.com/blog
    SITEURL: http://www.webdevireland.com/blog/wordpress
    PERMA STRUCTURE: /%year%/%monthnum%/%day%/%postname%/
    PATH INFO:
    REQUEST_URI: /blog/
    QUERY_STRING:
    SCRIPT_NAME: /blog/index.php
    SCRIPT_FILENAME: /home/user1/domains/webdevireland.com/public_html/blog/index.php
    PHP_SELF: /blog/index.php
    ERROR:
    FILE: /home/user1/domains/webdevireland.com/public_html/blog/wordpress/wp-content/plugins/dump_env.php
    WP Query String:
    WP_Query Query String:

    wp_query Object
    (
    [request] => SELECT DISTINCT * FROM blog_posts WHERE 1=1 AND post_date_gmt <= '2006-05-22 22:36:59' AND (post_status = "publish" OR post_author = 1 AND post_status != 'draft' AND post_status != 'static') AND post_status != "attachment" GROUP BY blog_posts.ID ORDER BY post_date DESC LIMIT 0, 10

    This error appears to happen when archive.php in the kubrick theme calls

    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Previous Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Next Entries »') ?></div>
    </div>

    next_posts_link() seems to be where it falls over.

    Appreciate any help you can give me filosofo.

  9. Austin Matzko
    Member
    Posted 6 years ago #

    evilhomer, I don't know what's going wrong. As I understand the error message you're getting, it's saying that there's nothing in [request] between SELECT DISTINCT * FROM and ORDER BY, but we can see that there's stuff there.

    In the file wp-includes/template-functions-links.php, does the first part of the next_posts_link function look like this? Because this is where the error is happening.

    function next_posts_link($label='Next Page &raquo;', $max_page=0) {
    global $paged, $result, $request, $posts_per_page, $wpdb, $max_num_pages;
    if ( !$max_page ) {
    if ( isset($max_num_pages) ) {
    $max_page = $max_num_pages;
    } else {
    preg_match('#FROMs(.*)sGROUP BY#siU', $request, $matches);
    $fromwhere = $matches[1];
    $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");

  10. evilhomer
    Member
    Posted 6 years ago #

    Filosofo, yeah my template-functions-links.php is exactly like that.

    When I click on an archive month it displays that message at the top of the screen.

    Is there anyway the $fromwhere would not be getting populated with a table name?

  11. serialdeviant
    Member
    Posted 5 years ago #

    My friend is having the same problem. Is there a solution?

  12. cromagnon99
    Member
    Posted 5 years ago #

    I have exactly the same problem, having upgraded from 1.5 to 2.0.3. Is any progress being made in resolving this?

    If there's any connection, I'va also had problems with updating permalinks - posted in a separate thread

  13. cromagnon99
    Member
    Posted 5 years ago #

    Only minutes after my original post . . . .

    For me, this problem disappeared once I had updated the Adhesive plugin - even though the old version of this was deactivated at the time of the problem.

    Hope this is other people's problem too.

  14. evilhomer
    Member
    Posted 5 years ago #

    cromagnon99, I don't use the Adhesive plugin.

    I still can't get rid of this, does anyone know anything else about it?

  15. akc
    Member
    Posted 5 years ago #

    Just upgraded from 1.5 to 2.0.3. At first I suspected my Connection theme had compatibility issues, but now it seems 1.5 themes should generally work with 2.0. I've opted for the default link structure, to no avail. Hosting company did upgrade to MySQL 4.1.19 recently -- don't know if this is an issue with PHP (caused me a lot of problems with Perl).

    PS: Deactivated all plugins -- same problem.

  16. CamWheeler
    Member
    Posted 5 years ago #

    I had this same problem when upgrading today. I found that some files on the FTP had not been overwritten with the new versions when uploading the 2.0.3 files, so I went through and deleted the files in the base directory except for wp-config.php and reuploaded. The problem was fixed for me after I did this.

  17. akc
    Member
    Posted 5 years ago #

    CamWheeler's right (thanks!): I was unknowingly running a "hybrid" version of 1.5 and 2.x. What happened was that some of the 2.0.3 files had dates older than those on my FTP directory.

  18. Steven
    Member
    Posted 5 years ago #

    If it helps anyone else I had the exact same problem and after reading CamWheeler's reply I tried deleting and reuploading my files one at a time. When I uploaded "wp-blog-header.php" in the root folder the error went away. I guess that means it was something inside that file that was popping the error.

  19. mciccio
    Member
    Posted 5 years ago #

    I completely agree with Stevenw721; i recently noticed this error message at the bottom of my home page at the end of the very last post:
    "WordPress database error: [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 '' at line 1]
    SELECT COUNT(DISTINCT ID) FROM "

    All i had to do was replace the current "wp-blog-header.php" on my server with a fresh copy of the same file.
    I downloaded 2.05 and only grabbed this file and over wrote the file. In my case the file on my server was newer than the file I was uploading.
    Everything works very well again and I am able to see the link for previous postings.

  20. SPman
    Member
    Posted 5 years ago #

    Well none of them didn't work for me. So I edited template like this...
    I found the code piece(it varies from template to template):

    if ( !$max_page ) {
    if ( isset($max_num_pages) ) $max_page = $max_num_pages;
    else {
    preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
    $fromwhere = $matches[1];
    $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
    $max_page = $max_num_pages = ceil($numposts / $posts_per_page);
    }
    }..........

    and replaced it by

    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Previous Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Next Entries »') ?></div>
    </div>

    found in default wordpress template. Now pagination is working normally and there is no any more errors.

Topic Closed

This topic has been closed to new replies.

About this Topic