PDO bind array to Where IN

后端 未结 4 1618
执念已碎
执念已碎 2021-01-23 18:29

I want to bind a array of Strings to the WHERE IN part of a SQL command, which I want to run afterwards on a SQL Server. The problem is probably that I try to bind

4条回答
  •  孤城傲影
    2021-01-23 19:05

    I faced similar problem with quite a big array to bind. Instead of skipping binding and injecting whole array directly to query or making workarounds with dynamically generating multiple unique placeholders to bind each record of array, I went for using find_in_set mysql function. Read more here.

    In your case it would be:

    $totalCount = 
    "SELECT referral, COUNT(username) AS cnt FROM accounts
    WHERE find_in_set(referral,$refIdsPartial) GROUP BY referral";
    

提交回复
热议问题