php - PDO binding values for MySQL IN statement -


I have an issue with PDO that I really want to like it in order to get answers after suffering for some time.

.

Take this example:

I am compelled to use the ID of a SDR in MySQL statement in a PDO statement.

The array will say: $ value = array (1,2,3,4,5,6,7,8);

Database-Safe Variables $ products =

Therefore, $ products STRING will: '1,2,3,4,5,6,7,8'

This statement will look like this:

  Choose users.id FROM to add user products to products.user_id = users.id where products IN (: product)  

Of course, $ products will force the statement : Products .

However, when the statement is compiled and values ​​are bound, it actually looks like this:

  Choose users.id FROM to add users products .user_id = users.id where products ('1,2,3,4,5,6,7,8')  

The problem is executed

What I really need is:

  select users to include products from users.id products.user_id = where on the users.id product IN (1,2,3,4,5 , 6,7,8)  

Only in fact can I do this I am putting the values ​​in without the string, but I know that there should be an easy way to do this.

This is the same thing that was asked in this question:

The answer was: In the section, for a variable size list in , you must create a query yourself.

However, you can use quoted, comma-separated list, though for large data sets, this can have a great impact, because every value in the table One has to be inserted for four types.

For example:

  Users choose products from products.user_id = users.id where find_in_set (cast (products as char. Id): Products)  

Or, as a third option, you can create a user-defined function that separates you from a comma Splits the list (cf.). This is probably the best choice for all three, especially if you have many questions that rely on (...) sections in .


Comments

Popular posts from this blog

MySql variables and php -

c# - How can I find out if there are windows above a control? -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -