Jump to content

Perpared Statements and Printing a Column on Screen?


Recommended Posts

The Connection:


$dsn = "mysql:dbname=phpblog;host=localhost";
$user = "root";
$password = "";
    $pdo = new PDO($dsn, $user, $password);
}catch(PDOException $e){
    echo "Connection failed: " . $e->getMessage();


The Script:


$query = $pdo->prepare("SELECT * FROM posts WHERE id = ?");
$query->bindValue("1", $_GET['post_id']);


I want to print the column "headline" on screen.


I know how to do it with a foreach loop:


foreach($query as $data){
    echo $data['headline'];

What can I do there?

Link to comment
Share on other sites

This thread is more than a year old.

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.