3 ms·
If you go the resilient route with everything you end up with code that looks like Java code. It's not usually worth it, as when the query changes, odds are yo
by Groxx 15y ago
If you go the resilient route with everything you end up with code that looks like Java code. It's not usually worth it, as when the query changes, odds are you'll be looking at the parameters, and will notice changes. Not true for large queries, of course, but for beginners? They're writing things like the above, where the entire process fits in a single eyefull. Making it more verbose from the get-go means they're more likely to just concatenate strings.
- masklinn 15y ago> If you go the resilient route with everything you end up with code that looks like Java code. Meh. Prepared statements are useful when you'll use the it multiple times through rebinding, and for one-shots it's easy enough to have a function taking a parameterized query and an array and doing the annoying crap internally. Then you just write: $result = executeSQL($somePDOObject, "INSERT INTO folks (name, addr, city) values (:name, :addr, :city);", array("name" => $name, "addr" => $addr, "city" => $city);
- eropple 15y agoThis is actually fairly close to what I do in my own code (I actually extend the PDO object, but same idea). The example I gave was just using the base PDO library instead.
- deleted 15y ago[deleted]