note 127644 added to mysql-xdevapi-crudoperationbindable.bind
| From: | MohammedalHambra at main dot php dot net | Date: | Fri, 16 Sep 2022 06:12:09 +0000 |
| Subject: | note 127644 added to mysql-xdevapi-crudoperationbindable.bind | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219588@lists.php.net to get a copy of this message | ||
I couldn't find any matching atricles for the CRUD operations in here. I hope this helps
anyone:
//create
public function create()
{
$sql = "INSERT INTO name(value1, value2, value3, value4) VALUES(?,?,?,?)";
$db = Database::connect();
$stmt = $db->prepare($sql);
$stmt->execute(array($this->value1, $this->value2, $this->value3,
$this->value4));
$lastID = $db->lastInsertId();
Database::disconnect();
return $lastID;
}
//update
public function update()
{
$sql = "UPDATE name SET value1= ?, value2=?, value3=? , value4= ? WHERE id=?";
$db = Database::connect();
$stmt = $db->prepare($sql);
$stmt->execute(array($this->value1, $this->value2, $this->value3,
$this->value4, $this->id));
Database::disconnect();
}
//read
public static function get($id)
{
$sql = "SELECT * FROM name WHERE id=?";
$db = Database::connect();
$stmt = $db->prepare($sql);
$stmt->execute(array($id));
$item = $stmt->fetchObject('Name');
Database::disconnect();
return $item !== false ? $item : null;
//read
public static function getAll()
{
$sql = "SELECT * FROM name";
$db = Database::connect();
$stmt = $db->prepare($sql);
$stmt->execute();
$items = $stmt->fetchAll(PDO::FETCH_CLASS, 'Name');
Database::disconnect();
return $items;
}
//delete
public static function delete($id)
{
$sql = "DELETE FROM nameWHERE id=?";
$db = Database::connect();
$stmt = $db->prepare($sql);
$stmt->execute(array($id));
Database::disconnect();
}
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.173 (proxied: 2001:4bb8:123:9f64:da8:7ce2:1289:7592)
----
Manual Page -- https://php.net/manual/en/mysql-xdevapi-crudoperationbindable.bind.php
Edit -- https://main.php.net/note/edit/127644
Del: integrated -- https://main.php.net/note/delete/127644/integrated
Del: useless -- https://main.php.net/note/delete/127644/useless
Del: bad code -- https://main.php.net/note/delete/127644/bad+code
Del: spam -- https://main.php.net/note/delete/127644/spam
Del: non-english -- https://main.php.net/note/delete/127644/non-english
Del: in docs -- https://main.php.net/note/delete/127644/in+docs
Del: other reasons-- https://main.php.net/note/delete/127644
Reject -- https://main.php.net/note/reject/127644
Search -- https://main.php.net/manage/user-notes.php