AfroNinja Posted October 2, 2008 Share Posted October 2, 2008 Much appreciation for any assistance on the following pdo topics! 1. The fetch() methods- can I just ignore these? The first example in a tutorial I read did a query like this: $result = $db->query($sql); foreach($result as $row) { //stuff } and from what I can tell, $result functions as both an associative array and a numerical array. Why then, would I need to use fetch and any of its associated parameters? Unless I explicitly need to fetch into an object or class, or I really need to display the column names (I should already know what they are if I'm fetching them) then it seems like I can skip the extra fetching... 2. Error handling. I switched from SILENT to WARNING. I use a try catch block on my actual database connection function so that my password doesn't display in case of an error, but I don't intend to use try catch blocks anywhere else unless I'm explicitly expecting mysql to return an error. (such as trying to insert duplicate data into a UNIQUE index column). Previously I made a custom query function that I passed $sql to and the function either did it or brought back an error. with PDO and prepared statements, writing an sql command isn't as straightforward. I noticed that when switching the errors to WARNING I got the same result as I would have previously anyway, so I was planning on leaving it like that. Any issues here? 3. bindValue vs bindParam. Most places I see use bindParam, so that the variables binded can later be changed and the query can be re-executed with different values. Should I use bindValue when I know this isn't the case and I'll only need to do the query once? 4. Skipping out on bindValue/Param. Related to the above- I saw someone mention that changing values in this fashion with bindParam wasn't good, and instead you should just do $stmt->execute($array_of_params) each time, changing the array as needed. This is fine, but when you bind a variable, that's when you state what type of data it is, IE PARAM_INT or PARAM_STR. If you skip this step, does PDO implicitly check the datatypes in order to properly sanitize the values? Link to comment https://forums.phpfreaks.com/topic/126826-some-pdo-questions/ Share on other sites More sharing options...
AfroNinja Posted October 3, 2008 Author Share Posted October 3, 2008 hmm... not many PDO users around here? Link to comment https://forums.phpfreaks.com/topic/126826-some-pdo-questions/#findComment-656548 Share on other sites More sharing options...
AfroNinja Posted October 5, 2008 Author Share Posted October 5, 2008 one more bump and I'll let it die, I promise Link to comment https://forums.phpfreaks.com/topic/126826-some-pdo-questions/#findComment-657416 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.