-4

The site used to run fine but all of a sudden i'm running into a DB Error 1064. You have an error in your SQL syntax; it seems the error is around: 'workspace_id ORDER BY id DESC LIMIT 0, 4' at line 8.

Can someone please help me see what i'm missing here

select * from notifications where !FIND_IN_SET($id, read_by) AND FIND_IN_SET($id, user_ids) AND workspace_id=$workspace_id ORDER BY id DESC LIMIT 0,4

PHP version: 7.3.6 Server version: 5.7.32-cll-lve - MySQL Community Server - (GPL)

  • (Possible) side note: Do not use string interpolation or concatenation to get values into SQL queries. That's error prone and might make your program vulnerable to SQL injection attacks. Use parameterized queries. – sticky bit Mar 20 '21 at 04:30
  • And normalize the schema. See ["Is storing a delimited list in a database column really that bad?"](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad). – sticky bit Mar 20 '21 at 04:31
  • And you should [edit] the question and provide a [example]. – sticky bit Mar 20 '21 at 04:32

1 Answers1

0

Are you trying to do it inside your views/controller/model?
Make sure you've loaded the database you wanted either from config autoload or manually from your controller/model.
In codeigniter 3 i usually use SQL syntax like (example) :

$this->db->query("SELECT * FROM table_name WHERE a = 'value' AND b = 'value 2' GROUP BY c DESC LIMIT 1, 4");