Wednesday, 11 July 2018

PHP PDO insert data:

PHP PDO insert data

<?php

// configuration

$dbhost        = "localhost";

$dbname        = "pdo";

$dbuser        = "root";

$dbpass        = "";

// database connection

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

// new data

$title = "ZEND FRAMEWORK TUTORIAL";

$author = "PHP Everyday";

$cover = fopen('7.png','rb');

// query

$sql = "INSERT INTO books2 (title,author,cover) values(?,?,?)";

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

$q->bindParam(1, $title);

$q->bindParam(2, $author);

$q->bindParam(3, $cover, PDO::PARAM_LOB);

$q->execute();

?>

0 comments:

Post a Comment