<div dir="ltr"><div>Hi Melanie and Rolando,</div><div><br></div><div>In fact, you can use pselect in this case. If you use pselect, you have to pass each "in" clause item as a parameter, not as a whole. For example, the following code could solve your problem.<br></div><div><br></div><div>$params = array();<br>$values = array();<br>foreach ($list as $key => $id) {<br> $params[] = ":id$key";<br> $values["id$key"] = $id;<br>}<br>$results = $DB->pselect(<br> "SELECT * FROM x WHERE ID in (" .<br> implode(', ', $params) . ")",<br> $values<br>)</div><div><br></div><div>Best regards,</div><div><br></div><div>Ling Ma</div><div>Development consultant<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 16, 2020 at 11:15 AM Melanie Legault, Mrs <<a href="mailto:melanie.legault2@mcgill.ca">melanie.legault2@mcgill.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hello Rolando,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Sorry if I misled you on the wrong track. You can't use `in` using pselect() or pselectOne().
<br>
In order to use `in` you have to use run().</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div id="gmail-m_8906812021652297979Signature">
<div id="gmail-m_8906812021652297979divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif">
<p style="margin-top:0px;margin-bottom:0px">M<span>é</span>lanie<br>
</p>
<br>
<p style="margin-top:0px;margin-bottom:0px"></p>
</div>
</div>
<div id="gmail-m_8906812021652297979appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_8906812021652297979divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> <a href="mailto:loris-dev-bounces@bic.mni.mcgill.ca" target="_blank">loris-dev-bounces@bic.mni.mcgill.ca</a> <<a href="mailto:loris-dev-bounces@bic.mni.mcgill.ca" target="_blank">loris-dev-bounces@bic.mni.mcgill.ca</a>> on behalf of Rolando Acosta <<a href="mailto:rolando.acosta@cnbp.ca" target="_blank">rolando.acosta@cnbp.ca</a>><br>
<b>Sent:</b> January 16, 2020 10:55<br>
<b>To:</b> <a href="mailto:loris-dev@bic.mni.mcgill.ca" target="_blank">loris-dev@bic.mni.mcgill.ca</a> <<a href="mailto:loris-dev@bic.mni.mcgill.ca" target="_blank">loris-dev@bic.mni.mcgill.ca</a>><br>
<b>Subject:</b> [Loris-dev] Issue when trying to use "pselectOne" and "pselect" functions with an " IN " sql statement</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi LORIS team, <br>
<br>
A while ago I faced the following issue in one of the PRs I was working on:<br>
<div><br>
</div>
<div>/////////////////////////////////////////</div>
<div><br>
</div>
The structure:<br>
<br>
$recruitmentStartDate = $DB->pselectOne(<br>
"SELECT MIN(Date_registered)<br>
FROM candidate<br>
<b> WHERE RegistrationCenterID IN (:Sites)",<br>
array('Sites' => implode(",", array_keys($list_of_sites)))</b><br>
);<br>
<br>
Doesn't seem to be working for me. Only the first element of the array $list_of_sites is been passed to the IN SQL clause. Not sure if I'm using correctly this way. For the moment I write it as:<br>
<br>
$recruitmentStartDate = $DB->pselectOne(<br>
"SELECT MIN(Date_registered)<br>
FROM candidate<br>
<b>WHERE RegistrationCenterID IN (" . $sitesString . ")",<br>
array()</b><br>
);<br>
<div><br>
</div>
<div>//////////////////////////////////////////////////</div>
<div><br>
</div>
<div><br>
</div>
I'm having the same behavior with the function <b>pselect(string $query, array $params): array</b><br>
from the <b>class Database</b>.<br>
<br>
I'm wondering if you could take a look and see if there is a way to pass an array as one of the elements in the
<b>$params</b> array? The issue rises when need to do an IN statement as part of the query.<br>
<br>
Cheers,<br>
Rolando Acosta (CHU Sainte-Justine)</div>
</div>
</div>
_______________________________________________<br>
Loris-dev mailing list<br>
<a href="mailto:Loris-dev@bic.mni.mcgill.ca" target="_blank">Loris-dev@bic.mni.mcgill.ca</a><br>
<a href="https://mailman.bic.mni.mcgill.ca/mailman/listinfo/loris-dev" rel="noreferrer" target="_blank">https://mailman.bic.mni.mcgill.ca/mailman/listinfo/loris-dev</a><br>
</blockquote></div>