I am new to PDO and not totally sure if I am looking for my desired usage in the right place/way.
PDO seems very nice but I find this kind of code rather long and don't want to use it for every query that I run:
$sth = $database->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour');
$sth->execute(array(':calories' => $calories, ':colour' => $colour));
I rather use something like this:
$array =
'calories' => $calories,
'colour' => $colour
);
$db->insert("fruit", $array);
(Similarly I'd like to make update calls, and I want this to work for each insert/update, so that the key name is taken as the field in the table, and the value as the value to insert/update).
What I value is:
- Having minimal code in my own scripts, using only arrays and dealing with the PDO statements (including error capturing) somewhere else.
- Still taking advantage of the prepared statements and object-oriented programming that comes with PDO.
I found many and answers but they propose many different types of solutions including:
All in all, there seem to be many options but I have no good idea of what the most recommended way is for my purpose, or even what the specific differences are.
Please illuminate me: what and where should I be looking for here?!