Paul-D Posted March 18, 2023 Share Posted March 18, 2023 Hi. I have tried to use the prepare and execute on a sample table of people. This should returm to people with first name Bruce. Not sure what this bindParam is all about. Picked it up on an IBM PDO web site. <? $pdo = connectDB(); $Name = "Bruce"; $sql= ("SELECT * FROM PDO WHERE Name_F = ?"); // $Name goes here $stmt = $pdo->prepare($sql); // $stmt->bindParam(1, $Name); $stmt->execute($Name); while ($row = $stmt->fetch()) { echo $row['Name_F'] . " - " . $row['Name_S'] . " - " . $row['DOB'] . "<br>"; } echo "Music count = " . $stmt->rowCount(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/316015-fetching-a-set-of-records-using-pdo-prepare-execute/ Share on other sites More sharing options...
ginerjm Posted March 18, 2023 Share Posted March 18, 2023 Soooo close! Try this since the execute wants an array as its argument: $stmt->execute([$Name]); Adding the brackets turns that arg from a string to an array. Voila! BTW - one should not use the * for a list of fields in the select statement. Always specify what you want to retrieve. As in: $q = "select Name_F, Name_S, DOB from ....... ' BTW #2 - is your table name really PDO? Quote Link to comment https://forums.phpfreaks.com/topic/316015-fetching-a-set-of-records-using-pdo-prepare-execute/#findComment-1606589 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.