-4

getting (syntax error or access violation 1064) dont know what is the problem. why i am getting this error? I think problen in my syntax with DATE

here is the screen with error: enter image description here

My code:

$sql = "SELECT ds.id
FROM documents ds
INNER JOIN institutions_if ib on ds.to_inst_id = ib.id
INNER JOIN documents_log dl on ds.id = dl.doc_id
WHERE
 ds.to_inst_id in :insts
 AND DATE(FROM_UNIXTIME(dl.timestamp)) = '2014-12-31' // <======== ERROR HERE!!!!!
 AND ds.status in ('sent','received','accepted','archived')
 AND ds.template_id = :template1
 AND NOT EXISTS (
 SELECT id FROM documents dr
 WHERE
 dr.reply_to = ds.id
 and dr.template_id = :template2
 and dr.status in ('sent','received','accepted','archived')
 and dr.to_inst_id in :insts
 );";
 $result = db_query($sql, array(
 ':insts' => institution_children_plan('[237, 279, 373]'),
 ':template1' => DocumentTemplate::get_template_by_handler('disp_suspend_operat_cont'),
 ':template2' => DocumentTemplate::get_template_by_handler('comun_anul_disp_susp_oper')
 ));
asked Jun 10, 2020 at 12:28
4
  • 2
    What happens if you remove that row? Commented Jun 10, 2020 at 12:29
  • What is this about Drush? Commented Jun 10, 2020 at 12:32
  • Hmm, error now in line "AND ds.status in ('sent','received','accepted','archived')" So I think problem in line "ds.to_inst_id in :insts", you see something wrong? Commented Jun 10, 2020 at 12:33
  • 2
    If you run into a problem like this, simply remove things until the problem is found. Commented Jun 10, 2020 at 12:37

1 Answer 1

0

You missed the () around the first IN content

WHERE ds.to_inst_id in (:insts)

so you have an error on the next AND

answered Jun 10, 2020 at 12:32
Sign up to request clarification or add additional context in comments.

4 Comments

as :insts will be bound as a string, have you tried this?
thk for you answer. But now I have new error :D
You can't use a param for a string and use as an array .. for this you need dinamic sql ..( string with sql concatenaed .. but check for content for avoid sql injection)
Or you could use several OR condition instead of an IN clause ..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.