php - Which method faster/better - multiple equal or IN? SQL -


i want know - method faster/better?

$string = ''; $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); for($i = 0; $i < 10; $i++){     if(!empty($string)){         $string .= ' or ';     }     $string .= ' `id` = '.$array[$id]; } 

or:

$array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $string = implode(', ', $array); $string = '`id` in ('.$string.')'; 

in sql:

'select * `table` '.$string 

in databases, 2 identical.

mysql, however, sorts in list , uses binary search. hence, in should faster multiple equals in mysql.

here reference:

returns 1 if expr equal of values in in list, else returns 0. if values constants, evaluated according type of expr , sorted. search item done using binary search.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -