Jump to content

Fetching a set of records using PDO prepare execute


Recommended Posts

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);

while ($row = $stmt->fetch())
	echo $row['Name_F'] . " - " .  $row['Name_S'] . " - " .  $row['DOB'] . "<br>";	
echo "Music count = " . $stmt->rowCount();


Link to comment
Share on other sites

Soooo close!

Try this since the execute wants an array as its argument:


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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.