Wednesday, 11 July 2018

PHP PDO view/revert/show data

PHP PDO view/revert/show data

<?php

// configuration

$dbhost        = "localhost";

$dbname        = "pdo";

$dbuser        = "root";

$dbpass        = "";

// database connection

$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);

// query

$sql = "SELECT id,title,author,cover FROM books2";

$q = $conn->prepare($sql);

$q->execute();

$q->bindColumn(1, $id);

$q->bindColumn(2, $title);

$q->bindColumn(3, $author);

$q->bindColumn(4, $cover, PDO::PARAM_LOB);

while($q->fetch())

{

file_put_contents($id.".jpg",$cover);

echo "$title, $author, &lt;img src='".$id.".jpg'&gt; &lt;br/&gt;";

}

?>

0 comments:

Post a Comment