CRUD using PDO in PHP: Insert data Part1

CRUD using PDO in PHP: Insert data Part1

learnWebCoding

6 лет назад

4,583 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Uche Michael Emelife
Uche Michael Emelife - 08.08.2020 03:19

# CRUD using PDO in PHP: Insert data Part 1
# book.php
<?php
/**
*
*/
class Book
{
protected $id;
protected $name;
protected $type;
protected $pages;
protected $price;
protected $author;
protected $createdDate;
private $tableName = 'books';
protected $dbConn;

function setId($id) { $this->id = $id; }
function getId() { return $this->id; }
function setName($name) { $this->name = $name; }
function getName() { return $this->name; }
function setType($type) { $this->type = $type; }
function getType() { return $this->type; }
function setPages($pages) { $this->pages = $pages; }
function getPages() { return $this->pages; }
function setPrice($price) { $this->price = $price; }
function getPrice() { return $this->price; }
function setAuthor($author) { $this->author = $author; }
function getAuthor() { return $this->author; }
function setCreatedDate($createdDate) { $this->createdDate = $createdDate; }
function getCreatedDate() { return $this->createdDate; }

public function __construct()
{
require_once('DbConnect.php');
$db = new DbConnect();
$this->dbConn = $db->connect();
}

public function insert()
{
$sql = "INSERT INTO $this->tableName VALUES(null, :name, :type, :pages, :price, :author, :cdate)";
$stmt = $this->dbConn->prepare($sql);
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':type', $this->type);
$stmt->bindParam(':pages', $this->pages);
$stmt->bindParam(':price', $this->price);
$stmt->bindParam(':author', $this->author);
$stmt->bindParam(':cdate', $this->createdDate);
if($stmt->execute())
{
return true;
}
else
{
return false;
}
}
}
?>

Ответить
Felix Omuok
Felix Omuok - 26.08.2019 19:38

link to the getter abd setter site

Ответить
hoàng phan
hoàng phan - 15.05.2019 12:52

Can you give me the code?

Ответить