简体   繁体   中英

PHP mysqli_query reports syntax error

string(150) "
    SELECT * 
    FROM (
        SELECT *, @row := @row +1 AS rownum 
        FROM (SELECT @row :=0) r, `coordinates` 
        WHERE fid='3'
    ) ranked 
    HAVING rownum % FLOOR(@row/20) = 1
" 

$result = mysqli_query($link, $sql);

Connect 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 ' FROM (SELECT *, @row := @row +1 AS rownum FROM (SELECT @row :=0) r, `coordina' at line 1

The first line is a var_dump of my $sql variable, but the sql works just fine from command line. It reports an error when using the PHP.

Why is this, and how can I fix it?

This is just so weird, sorry that I do not know what the issue is but the $sql that is not commented out does not work and has string (150), but the $sql that is commented out works and is string (147), the editor is coda 2 on mac, and there are no spaces between "ranked" and "HAVING"

错误

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM