Many SQL indent are wrong : 

```
        $sql = 'REPLACE INTO records_rights
                (
                    SELECT null as id, usr_id, b.sbas_id, record_id, "1" as document, null as preview,
                        "push" as `case`, pushFrom as pusher_usr_id
                    FROM sselcont c, ssel s, bas b
                    WHERE c.ssel_id = s.ssel_id
                        AND b.base_id = c.base_id AND c.canHD = 1
                 )';
```

Please note moving commas at end of line instead of beginning. re-indent if the new line does not begin with an SQL keyword or is a constraint description