Wednesday 11 July 2018

Insert data using php PDO

Insert data using php PDO


<?php

// configuration
$dbhost        = "localhost";
$dbname        = "";
$dbuser        = "root";
$dbpass        = "";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);

// new data
$title = 'PHP Security';
$author = 'Jack Hijack';
// query

$sql = "INSERT INTO books (title,author) VALUES (:title,:author)";
$q = $conn->prepare($sql);
$q->execute(array(':author'=>$author,':title'=>$title));
?>

0 comments:

Post a Comment