PDO is very weak with such cases, so the task will be quite difficult.
Like any other API, PDO is good for basic tasks only from a beginner's guide and does not offer real developer assistance for any problems in real life.
Therefore, the developer must accept some kind of abstraction library to allow it to do all the dirty work.
So, I will give you a safeMysql example that is better than PDO in any way:
$nba[0] = "Boston Celtics"; $nba[1] = "New York Knicks"; $nba[2] = "Houston Rockets"; $query = "SELECT game_id FROM table WHERE date_int >= ?i AND (home_team = ?s OR away_team = ?s) AND home_team IN(?a) AND away_team IN(?a) ORDER BY game_date_int ASC LIMIT 1"; $data = $db->getAll($query, $limit, $team, $team, $nba, $nba);
Take a look - this code is neat, concise, and specific. It does only meaningful things, hiding all the dirty work of linking complex data inside. Unlike ugly codes, you can play with some PHP and API functions, this code is readable . It is important. You can tell what this code does even after a year or so.
NLZ's answer is a great example - the code is polluted with unnecessary and rather cryptic code.
When you are looking for your code, you are looking for business logic in the first place. And such useless code blocks, designed only to create a small part of the SQL query, will make you dizzy, hiding real questions from you.
In should move somewhere behind.
source share