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')
));
-
2What happens if you remove that row?jarlh– jarlh2020年06月10日 12:29:59 +00:00Commented Jun 10, 2020 at 12:29
-
What is this about Drush?norman.lol– norman.lol2020年06月10日 12:32:19 +00:00Commented 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?Nick– Nick2020年06月10日 12:33:08 +00:00Commented Jun 10, 2020 at 12:33
-
2If you run into a problem like this, simply remove things until the problem is found.jarlh– jarlh2020年06月10日 12:37:27 +00:00Commented Jun 10, 2020 at 12:37
1 Answer 1
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
ScaisEdge
134k10 gold badges98 silver badges111 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
Nigel Ren
as
:insts will be bound as a string, have you tried this?Nick
thk for you answer. But now I have new error :D
ScaisEdge
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)
ScaisEdge
Or you could use several OR condition instead of an IN clause ..
default